Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for partial words using Solr

Tags:

solr

sunspot

I'm trying to search for a partial word using Solr, but I can't get it to work.

I'm using this in my schema.xml file.

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer type="index">
      <tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="15" />
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
       <filter class="solr.StandardFilterFactory"/>
       <filter class="solr.LowerCaseFilterFactory"/>
       <filter class="solr.PorterStemFilterFactory"/>
       <filter class="solr.WordDelimiterFilterFactory" stemEnglishPossessive="1" splitOnNumerics="1" splitOnCaseChange="1" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="1" preserveOriginal="1"/>
  </analyzer>
</fieldType>

Searching for die h won't work, but die hard returns some results. I've reindexed the database after the above configuration was added.

Here is the url and output when searching for die hard. The debugger is turned on.

Here is the url and output when searching for die h. The debugger is turned on.

I'm using Solr 3.3. Here is the rest of the schema.xml file.

like image 581
Linus Oleander Avatar asked Oct 08 '11 14:10

Linus Oleander


People also ask

How do I search exact match in SOLR?

You have to use PhraseQuery ( text:"Richard Chase" ) to get documents where both Ricahard and Chase are near to each other. If you want also to find, say, Richard X. Chase you can use text:"richard chase"~1 . This will not return exact matches as results like "Richard Chase Jr" would be returned.

How does SOLR search work?

Solr works by gathering, storing and indexing documents from different sources and making them searchable in near real-time. It follows a 3-step process that involves indexing, querying, and finally, ranking the results – all in near real-time, even though it can work with huge volumes of data.

How do I run a Solr query?

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.

What is SOLR query?

In addition to storing data, Apache Solr also provides the facility of querying it back as and when required. Solr provides certain parameters using which we can query the data stored in it.


1 Answers

The query you've shared is searching the "title_text" field, but the schema you posted above defines the "text" field. Assuming this was just an oversight, and the title_text field is defined as in your post, I think a probable issue is that the NGramTokenizer is configured with minGramSize="3", and you are expecting to match using a single-character token.

You could try changing minGramSize to 1, but this will inevitably lead to some very inefficient indexes; and I wonder whether you really are keen on having "e" match every movie with an e in the title?

like image 157
Mike Sokolov Avatar answered Sep 28 '22 13:09

Mike Sokolov