Yasir Malik
Yasir Malik

Reputation: 51

SOLR - Exact Matching with Phrase and Boolean Search

We need some help getting our SOLR deployment to work with EXACT MATCH search capability.

Specifically, we have a text type field in the schema and we want to apply an Exact Match Search with Phrase and Boolean Searches as well.

For example:

User enters:

DIRECTOR AND (FINANCE OR CONTROLLER OR ACCOUNTING)

…..But unfortunately, the results return records with words like:

ACCOUNT

CONTROLLING

Etc.

So essentially, SOLR is searching inside words – which of course we do not want. (Yes, it is at least prioritizing these results at the very END of a set of results…but still, our users want precise matches that the ‘Exact Match’ search is supposed to deliver.

We thought about changing the field to STRING instead of TEXT type, but STRING does not play well with phrase and Boolean searches.

Upvotes: 4

Views: 2124

Answers (2)

delkant
delkant

Reputation: 2294

You can create/duplicate this field with a different dataType.

so you will have.

schema.xml

<field name="title" type="text"  indexed="true" stored="true"/> 
<field name="titleExactMatch" type="string"  indexed="true" stored="true"/> 

 <copyField source="title" dest="titleExactMatch"/>

and then overwrite the " weights of the search" redefining qf.

solrconfig.xml

<requestHandler name="/select" class="solr.SearchHandler">
<!-- default values for query parameters can be specified, these
     will be overridden by parameters in the request
  -->
 <lst name="defaults">
   <str name="df">titleExactMatch</str>
   <str name="echoParams">explicit</str>
   <int name="rows">10</int>       
   <str name="defType">edismax</str>
   <str name="qf">titleExactMatch^2.2 title^0.4</str>
   <str name="sort">score desc, _version_ desc, title desc</str>
 </lst>

Notes: I haven't tested this config but it should give you the results your are asking for or at least in the order you need them.

Upvotes: 2

Mike Sokolov
Mike Sokolov

Reputation: 7054

You need to disable stemming. If you look in your Solr schema.xml file you'll find definitions of the fields and field types that control the kind of processing that's done on each field. Most likely you just grabbed the default and have not configured this at all? I suggest you take some time to understand the options in that file; they're well documented on the solr wiki. But the thing you are asking about is most likely the effect of the PorterStemFilter, so you might try just commenting that out and reloading your data.

Upvotes: 2

Related Questions