Reproduced http://www.colorfuldays.org/program/solr/solr%E6%89%A9%E5%B1%95dismaxqparser/
Recently, my colleagues in the product gave me a question about the search. When users enter "queryparser Customization", they cannot find the search results, but the search "queryparser Customization" can find the correct results. This problem leads to a high failure rate in search. I started to solve the problem the day before yesterday. After two days of research, I finally customized queryparser to solve the problem. The solution to this problem is to customize the queryparser of SOLR. The following describes how to customize the queryparser of SOLR.
Our search engine uses the edismax type. Because some businesses need to use the features provided by edismax, they can only be customized on edismax.
Perform a word segmentation test. The word segmentation result of "queryparser Customization" is consistent with that of "queryparser Customization.
Open debugquery and compare "queryparser custom" with "queryparser custom" to output querystring.
"Queryparser Customization" is displayed as follows:
"Parsedquery": "+ (disjunctionmaxquery (goods_title: queryparser ))
Disjunctionmaxquery (goods_title: custom )))~ 2 )",
"Queryparser Customization" is as follows:
"Parsedquery": "+ disjunctionmaxquery (goods_title: \" queryparser custom \"))",
We can see from the above two results that although the word segmentation is correct, edismax's processing method is not as expected and can only be solved by modifying the source code.
Find the corresponding code extendeddismaxqparserplugin. java. After studying the process through debug, find out where to modify it.
After modifying the source code, compress the class into Lib. The deployment method is as follows:
1. Put the prepared package under $ {SOLR. Home}/lib to ensure that SOLR will be loaded to this jar at startup.
2. modify the configuration below solrconfig. xml:
Add a new queryparser:
<Queryparser name = "newdismax" class = "com. server. SOLR. newextendeddismaxqparserplugin"/>
Use the new queryparser:
<requestHandler name="/browse" class="solr.SearchHandler"> <lst name="defaults"> <str name="echoParams">explicit</str> <str name="wt">json</str> <str name="json.ml">map</str> <str name="defType">newdismax</str> <str name="rows">20</str> <str name="mm">1</str> <lst> </requestHandler>
Note that the name in newextendeddismaxqparserplugin must be changed to newdismax. As follows:
Public static final string name = "newedismax ";
After SOLR is restarted, you can use the new queryparser. You can customize this class to meet other requirements.