简体   繁体   中英

How to perform both exact search and stemmed search on the same field depending upon the operator in solr

I get search request in the form of a java object out of which i construct a SOLR query object and query the index.

For example assume user wants to do an exact search on a field called title. He would send a query of the form

  Field = "title", value = "Algebra", Operator = "EQUALS"

When i see the operator as "EQUALS", construct a solr query like this

  title:Algebra

For a wild card or stemmed search, request would be something like this,

  Field = "title", value = "Algebra", Operator = "LIKE"

As the operator is "LIKE" solr query I am constructing is,

  title:*Algebra*

The problem here is for wild card and other stemmed options to work title field is defined as text_general and text(through copy field option) in my schema.xml, so when i use operator ":" it does stemmed search and retrieves me results that have Algebra word in the title field where as output I am expecting is just the records with title as Algebra.

I know one solution where i need to change title field as "string" in configuration file. But this would effect my stemmed search and wild card search options.

So basically i want a field to support both stemmed search (and all other text_general field options) as well as exact match based on the operator i pass to it. Is it even possible. If so pl guide me how to accomplish the same.

You'll have to have two fields, one for the stemmed / processed version, and one for the clean string version. Use <copyField> to make sure that both gets populated when indexing.

While there are no "global" conventions for this, I'd suggest adopting a naming convention for the field name depending on it's processing. If you have fieldname as string, you have fieldname_stemmed as the text field (or fieldname_text), if you see Operator = 'LIKE', append _stemmed or _text to the fieldname. You can also do it the other way around, have the regular fieldname be stemmed and processed, while you have fieldname_clean as the exact version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM