Question

On a solr 4, I'm making a query for a word "black" and it returns me the results of the only product that have exact word - "black" in the name & desc. I'm searching only on the name and description.

However, there are many words that I want to include in search results.. like the result should include.. Jadeblack, Superblack, blackblue, nightblack and other words that have black in the string anytwhere and not just the word black.

However, such results are lesser relevant and should be ranked after results that have word "black".

Can you advise how should I change to get this kind of results.

Was it helpful?

Solution

Would suggest to use two fields. Copy Field the text_exact field to text_ngram field.

  1. text_exact - Exact match which will be boosted higher
  2. text_ngram - An ngram field which will help you to match partial matches with a boost lower than the exact match

You can configure the boost as text_exact^2 text_ngram^0.5

OTHER TIPS

You can use wildcards in your search term on a string type field. For example:

name:*black* OR description:*black*

With this search you get any results that have "black" in "name" or "description" and it doesn't have to be an exact match. In order to sort according to the quality of the match i think you would have to define a boost for the exact match and sort by the score. But this i have not done yet.

Just in case you didn't know yet. Searches on the type string are case sensitive by default. So you would not find matches for "Black" (except you really have a document where it is written in capital case). To change this behaviour you must define your own case insensitive string type:

<fieldType name="string_ci" class="solr.TextField" sortMissingLast="true" omitNorms="true">
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

But this doesn't work for wild card search (as for "black"). In that case you would have to transform every search term that should include wildcards to lower case before sending to solr.

A different solution would be to use a different type (for example "text") instead of "string".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top