edigu
edigu

Reputation: 10089

Why solr dismax query returns empty resultset?

I'm trying to get free-text search results from indexed data with solr 4.5 using Dismax Query Parser but no results returning and no errors with simple queries like this:

http://localhost:9999/solr/products/select?q=cuir&qf=text_fr&defType=dismax

And these documents are exists in index:

{ id: 1, label: "Sac à main en cuir" }
{ id: 2, label: "Sac à main en cuir rouge" }

My schema.xml is:

..
<field name="id" type="int" indexed="true" stored="true" required="true" /> 
<field name="label" type="string" indexed="true" stored="true" required="true" />
...
<copyField source="label" dest="label_fr"/>
<dynamicField name="*_fr" type="text_fr" indexed="true" stored="false" />
...
<fieldType name="text_fr" class="solr.TextField" positionIncrementGap="100">
  <analyzer> 
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords_french.txt" enablePositionIncrements="true" />
    <filter class="solr.SnowballPorterFilterFactory" language="French"/>
    <filter class="solr.CollationKeyFilterFactory" language="fr" strength="primary" />
  </analyzer>
</fieldType>

and in solrconfig.xml

...
<requestHandler name="/select" class="solr.SearchHandler">
  <lst name="defaults">
    <str name="echoParams">explicit</str>
    <int name="rows">10</int>
    <str name="defType">dismax</str>
  </lst>
 ...

So any ideas what is wrong? Why there are no results?

Upvotes: 1

Views: 1507

Answers (2)

Murtaza Kanchwala
Murtaza Kanchwala

Reputation: 2483

In the above schema you've defined the field "label" as "string" and it is treating it as a single string

You Should change the fieldType to :

<field name="label" type="text_general" indexed="true" stored="true" required="true" />

And as mentioned above the text_general fieldType by default has the StandardTokenizerFactory configured.

It'll treat the field as text (or strings) and you will be able to perform full-text search on it.

Note : FieldType String is good in case of faceted search for a particular category in that case you must use String for better results. or you can do a CopyField.

Upvotes: 0

taleodor
taleodor

Reputation: 2061

KeywordTokenizer treats your whole index string as a single token, so it won't match to a single word query.

Instead, you may try StandardTokenizerFactory, or WhitespaceTokenizerFactory, or WordDelimiterFilter.

Upvotes: 2

Related Questions