Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure SOLR to find documents if the plural is used in the document, and the singular in the search text?

Tags:

solr

I am using solr, set up at localhost:8983 I am basically using the out of the box example. I have entered one document with a name "Car", and another with a name "Cars".

If I visit either:

http://localhost:8983/solr/select?q=Car

or

http://localhost:8983/solr/select?q=Cars

I would expect to get both documents. At the moment, I don't.

In the fields tag of "schema.xml", the entry for "name" is:

"text_general" has the following "analyzers" (without the stemmers):

<analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
</analyzer>

I tried to add a stemmer to each analyzer. I tried:

<filter class="solr.PorterStemFilterFactory"/>
<filter class="solr.KStemFilterFactory"/>
<filter class="solr.EnglishMinimalStemFilterFactory"/>

Doing so makes it such that searching for "Cars" will find "Car", but I can never find "Cars".

Should it be possible to find "Cars"?

Any help would be greatly appreciated. Thank you.

like image 598
zod Avatar asked Jan 31 '12 19:01

zod


People also ask

How do I search for a specific field in Solr?

If you do not specify a field in a query, Solr searches only the default field. Alternatively, you can specify a different field or a combination of fields in a query. To specify a field, type the field name followed by a colon ":" and then the term you are searching for within the field.

How do you create a query in Solr?

Trying a basic query The main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.

How do I query in Solr collection?

You can search for "solr" by loading the Admin UI Query tab, enter "solr" in the q param (replacing *:* , which matches all documents), and "Execute Query". See the Searching section below for more information. To index your own data, re-run the directory indexing command pointed to your own directory of documents.


2 Answers

It is possible, just add porter filter at the end (after LowerCaseFilterFactory):

<filter class="solr.SnowballPorterFilterFactory" language="English" />

Read more:

  1. Snowball docs with example of use in analyser
  2. Solr LanguageAnalysis
  3. The English (Porter2) stemming algorithm

If there is no special need, I would not divide analyser to index and query time. Your query time analyser looks perfectly good to use it in both cases.

like image 55
Fuxi Avatar answered Nov 07 '22 12:11

Fuxi


I found that changing from text_general to text_en in the shema.xml fields took care of this plurality problem

like image 36
Jules Avatar answered Nov 07 '22 12:11

Jules