Reputation: 606
Wasn't quite sure how to word the title of this. Basically, when I search for 'anim' it finds 'animals', however when I search for 'anima' it doesn't find anything. Then if I search for 'animal' it finds 'animals' again...
Does anyone have any ideas why it might not be working for 'anima'? It seems to happen for most words - but at different characters - e.g. 'eleph' and 'elephan' are fine - but 'elepha' doesn't return anything.
Here are the queries and results:
Query 1 (okay)
/solr/select?fq=type:tag&q=name:anim
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="fq">type:tag</str>
<str name="q">name:anim</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<int name="id">1</int>
<str name="name">Animals</str>
<arr name="name_auto">
<str>Animals</str>
<str>Animals</str>
</arr>
<date name="timestamp">2012-08-01T08:16:38.789Z</date>
<str name="type">tag</str>
<str name="unique_id">tag_1</str>
</doc>
</result>
</response>
Query 2 (not okay)
/solr/select?fq=type:tag&q=name:anima
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="fq">type:tag</str>
<str name="q">name:anima</str>
</lst>
</lst>
<result name="response" numFound="0" start="0"/>
</response>
Query 3 (okay)
/solr/select?fq=type:tag&q=name:animal
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="fq">type:tag</str>
<str name="q">name:animal</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<int name="id">1</int>
<str name="name">Animals</str>
<arr name="name_auto">
<str>Animals</str>
<str>Animals</str>
</arr>
<date name="timestamp">2012-08-01T08:16:38.789Z</date>
<str name="type">tag</str>
<str name="unique_id">tag_1</str>
</doc>
</result>
</response>
Edit 1:
Field definition
<field name="name" type="text" indexed="true" stored="true" required="true" />
fieldType:
<fieldType name="text" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<!-- Case insensitive stop word removal.
add enablePositionIncrements=true in both the index and query
analyzers to leave a 'gap' for more accurate phrase queries.
-->
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="stopwords.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="stopwords.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType>
Edit 2:
Passing strings though the Analyser:
Upvotes: 0
Views: 494
Reputation: 60205
Ansari is right, the problem is due to stemming. The Solr schema you posted proves it since you're using the PorterStemFilterFactory
. If you want to search for partial word you can try with wildcard queries, depending on the query parser you're using. If you're using SOlr 3.x they might be too slow, while with Solr 4.x this has been improved a lot. You might want to make EdgeNGrams then, so that anima
match animals
too.
Upvotes: 1