Solr edismax boost query
Before starting keep in mind that SolrDisMaxQuery class was not part of the 2.0.0 release.
But still you can download the current master branch from following link:-
http://git.php.net/?p=pecl/search_engine/solr.git;a=shortlog;h=refs/heads/master
With eDismax you can filter you result with more accuracy and boost your query with extra params
Like if you want to search doctor on basis of First Name, Middle Name and Last Name. Normal query will search your string in all these filed like
You typed Rajeev Kumar then normal query will search like
First Name = Rajeev
Middle Name = Rajeev
Last Name = Rajeev
First Name = Kumar
Middle Name = Kumar
Lat Name = Kumar
But you want to check exact combination in order first-middle-last Name then eDismax query is super power for you.
I am explaining with code example
- Creating connection parameter for Solr server
$optionsEdimax = array                (                'hostname' => "localhost",               'login'   => "admin",                'password' => "",               'port'    => "8399",                'path'    => '/solr/doctor_list,                'wt'          => "json",                'indent' => 1,                );
- Initialize object
$client = new SolrClient($optionsEdimax);
- initialize Dismax object
$dismaxQuery = new SolrDisMaxQuery();
- Allow to use eDismax Query Parser
$dismaxQuery->useEDisMaxQueryParser();
- Add query string
$queryStr = "first_name=Rajeev Kumar* middle_name= Rajeev Kumar* Â Â last_name= Rajeev Kumar*"
- Pass query string in eDismax Query
$dismaxQuery->setQuery($queryStr);
- Add extra prams like no of fetch records
$dismaxQuery->setRows(10);
- Now main part of eDismax Query like how much probability you want in terms
$dismaxQuery->addQueryField("first_name", 1.5); $dismaxQuery->addQueryField("middle_name", 1.5); $dismaxQuery->addQueryField("last_name", 1.5);
Means equal search in all three field for all keywords.
- And what is the calculation of minimum match
$dismaxQuery->setMinimumMatch("1<-75% 2<-2");
means if only single word then match 25% and if more than one word then will match 75%
http://lucene.apache.org/solr/5_0_0/solr-core/org/apache/solr/util/doc-files/min-should-match.html - Now time to run your query for response
$query_response = $client->query($dismaxQuery);
- Get response
$response = $query_response->getResponse();
That’s it with above simple step you can Boost your search results with normal search.
For more parameter passing you can check below link
https://wiki.apache.org/solr/ExtendedDisMax
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016