cp apache-solr-1.4.0/dist/apache-solr-1.4.0.war /data/solr/dist cp -R apache-solr-1.4.0/example/solr/* /data/solr/
<Context docBase="/data/solr/dist/apache-solr-1.4.0.war" debug="0" crossContext="true" reloadable="true">
<Environment name="solr/home" type="java.lang.String" value="/data/solr" override="true" />
</Context>
<fieldType name="text_cn" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.CJKTokenizerFactory"/>
</analyzer>
</fieldType>
<fieldtype name="text" class="solr.TextField">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.StopFilterFactory"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldtype>
cp /usr/local/src/apache-solr-1.4.0/dist/apache-solr-1.4.0.war /usr/local/apache-tomcat-6.0.20/webapps/
<Context docBase="/data/solr/dist/apache-solr-1.4.0.war" debug="0" crossContext="true" >
<Environment name="solr/home" type="java.lang.String" value="/data/solr/example/multicore" override="true" />
</Context>
通过api添加core
优化: http://211.100.42.68:8180/solr/update?optimize=true&maxSegments=10&waitFlush=false
提交: http://211.100.42.68:8180/solr/update?commit=true
删除:
<delete><id>SP2514N</id></delete> <delete><query>type:bbs</query></delete>
查询 http://211.100.42.68:8180/solr/select?indent=on&version=2.2&q=contents%3A%E6%90%9C%E7%8B%90&fq=&start=0&rows=10&fl=*%2Cscore&qt=standard&wt=php&explainOther=&hl=on&hl.fl=title%2Ccontents
termVectors="true"
http://61.150.91.179:8180/solr/core6/select/?q=id:2&mlt=true&mlt.fl=title,txt&mlt.mindf=1&mlt.mintf=1&fl=id,score,url,title&%20mlt.match.include=true
1. xml中不能包括 & ,遇到应该替换为&
2. post时一定要加Content-Type: text/xml的header,不然会包400错 PHP
$xml = "<add><doc> ... </doc></add>"; $header[] = "Content-Type: text/xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $data = curl_exec($ch); if (curl_errno($ch)) { echo " curl error:", curl_error($ch); } else { curl_close($ch); }
python:
try: req = urllib2.Request(posturl,data=xml) #req.add_header('Content-Type', 'text/xml') f = urllib2.urlopen(req) print 'read:', f.read() except urllib2.HTTPError, e: print e except Exception, e: print e
3. 简单的示例已经完成了,索引文件(默认)会在 CWD/solr/data/index 目录下,要改为 solr.home/data目录下,在 F:\apache-solr-1.3.0\example\solr\conf\solrconfig.xml 把 dataDir 注释掉,如:
<!--
<dataDir>${solr.data.dir:./solr/data}</dataDir>
-->