Solr/Dismax with dynamic fields

1.5k views Asked by At

I just added some wildcard dynamic fields to my solr schema:

<dynamicField name="*_s" type="string" indexed="true" stored="true"/>

Then I add a document with field name like asdfasdf_s

If I do a query that brings up this document, I see that asdfasdf_s is stored in the results with the value I set.

However, if I search by the value in that dynamic field, I get no results. I am using the dismax query parser.

1

There are 1 answers

1
Paige Cook On BEST ANSWER

This is most likely because you have type field type of your dynamic fields set to string. By default the string field type, as shown below is not overly search friendly, as it does not have any index or query time analyzers associated with it.

<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>

I would suggest that you change to something like the text_general field type as shown below.

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <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>
</fieldType>

As the text_general is better suited to querying the field as it tokenizes, lowercases and provides synonyms for values added to it. One quick way to gain the same benefits without changing your field type for the dynamics would be to use copyField to copy your dynamic values to a text_general field type or some other field type that would be better to querying against.