第6章 改进solr的性能
1. Paging your results quickly,编辑solrconfig.xml:
<queryResultWindowSize>160</queryResultWindowSize>
<queryResultMaxDocsCached>160</queryResultMaxDocsCached>
2. 配置document缓存,编辑solrconfig.xml:
<documentCache class="solr.LRUCache" size="2560" initialSize="2560"/>
3. 配置query result缓存,编辑solrconfig.xml:
<queryResultCache class="solr.LRUCache" size="16000" initialSize="16000" autowarmCount="4000"/>
4. 配置filter缓存,编辑solrconfig.xml:
<filterCache class="solr.FastLRUCache" size="2000" initialSize="2000" autowarmCount="1000"/>
5. 。。。
第8章
1. 相似度查询
/select?q=cookbook second
&mm=2
&qf=name
&defType=edismax
&mlt=true
&mlt.fl=name&
&mlt.mintf=1
&mlt.mindf=1
2. 高亮显示
/select?q=name:book
&hl=true
3. 高亮显示指定的字段
/select?q=name:book
&hl=true
&hl.fl=name,description
4. 改变高亮显示词两边的html标签
/select?q=name:book
&hl=true
&hl.simple.pre=<b>
&hl.simple.post=</b>
5. 如何高亮显示长文本中的词
<field name="name" type="text" indexed="true" stored="true"
termVectors="true"
termPositions="true"
termOffsets="true" />
/select?q=name:book
&hl=true
&hl.useFastVectorHighlighter=true
6. 计算统计搜索结果
/select?q=name:book
&stats=true
&stats.field=price
7. 检查用户的拼写错误
/spell?q=name:(othar boak)
配置solrconfig.xml:
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">name</str>
<lst name="spellchecker">
<str name="name">direct</str>
<str name="field">name</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">name</str>
<str name="spellcheck.dictionary">direct</str>
<str name="spellcheck">on</str>
<str name="spellcheck.collate">true</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
8. Using field value to group results
/select?q=*:*
&group=true
&group.field=category
9. More than a single document in a group
/select?q=*:*
&group=true
&group.field=category
&group.limit=10
10. Using queries to group results
/select?q=*:*
&group=true
&group.query=price: [20.0 TO 50.0]
&group.query=price:[1.0 TO 19.99]
11. Using function queries to group results
/select?q=*:*
&group=true
&group.func=geodist(geo,0.0,0.0)
第9章
1. How to deal with too many opened files
异常:java.io.FileNotFoundException: /use/share/solr/data/index/_1.fdx (Too many open files)
编辑/etc/security/limits.conf
solr soft nofile 32000
solr hard nofile 32000
Now let's add the following line to the .bash_profile file in the solr user home directory:
ulimit -n 32000
编辑solrconfig.xml
<mergeFactor>2</mergeFactor>
2. How to deal with out-of-memory problems
异常:SEVERE: java.lang.OutOfMemoryError: Java heap space
java –Xmx1024M –Xms512m –jar start.jar
Monitoring heap when an out-of-memory error occurs
java –jar –XX:+HeapDumpOnOutOfMemoryError –XX:HeapDumpPath=/var/log/dump/ start.jar
3. 诊断solr的问题
vmstat, dstat, and iostat
jconsole and jvisualvm
使用http://sematext.com/spm/index.html监测solr
还可以使用:
http://ganglia.sourceforge.net/
http://munin-monitoring.org/
http://www.zabbix.com/
http://www.cacti.net
http://newrelic.com/
4. 查询某分类下的产品数量(以牛奶开头的产品)
/select?q=*:*&rows=0
&facet=true
&facet.field=category
&facet.mincount=1
&facet.limit=5
&facet.prefix=牛奶
5. ???
/select?q=*:*&defType=edismax&fq={!term f=category}Books And Tutorials
6. 提交xml文档
curl 'http://localhost:8983/solr/update' --data-binary @data.xml -H 'Content-type:application/xml'
curl 'http://localhost:8983/solr/update?softCommit=true'
7. solrconfig.xml中配置autoCommit
<autoCommit>
<maxTime>60000</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>
<autoSoftCommit>
<maxTime>1000</maxTime>
</autoSoftCommit>
8. ???
/select?q=solr book
&defType=edismax
&mm=1
&qf=name^10000 description