thebernardlim
thebernardlim

Reputation: 830

Solr - Suggester custom field not detected & Multiple fields cannot work

Goal

Trying to implement an auto-suggester in Solr. Fields to extra suggestions from are title and content fields.

Progress thus far

I followed the official Solr guide to implement the feature, however, was stuck for a long time, as it was complaining that the custom field suggestType was not defined.

After a long time of trying I decided to add the field type to managed-schema.xml instead of schema.xml and it worked!

Thus far, it only worked when I based the suggestion field off content, however, we would like to use 2 fields to base suggestions of which is title and content.

Steps followed

1) Add custom field type in managed-schema xml:

<fieldType name="suggestType" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
        <charFilter class="solr.PatternReplaceCharFilterFactory" pattern="[^a-zA-Z0-9]" replacement=" " />
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

2) Add custom field which uses custom field type in schema.xml:

<field name="suggestText" type="suggestType" stored="true" indexed="true" />

3) Add 'suggest' handler in solr-config.xml:

<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
    <str name="name">fuzzySuggester</str>
    <str name="lookupImpl">FuzzyLookupFactory</str>
    <str name="storeDir">fuzzy_suggestions</str>
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>
    <str name="field">suggestText</str>
    <str name="suggestAnalyzerFieldType">suggestType</str>
    <str name="buildOnStartup">false</str>
    <str name="buildOnCommit">false</str>
    </lst>
</searchComponent>

<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy" >
    <lst name="defaults">
        <str name="suggest">true</str>
        <str name="suggest.dictionary">analyzingSuggester</str>
        <str name="suggest.onlyMorePopular">true</str>
        <str name="suggest.count">10</str>
        <str name="suggest.collate">true</str>
    </lst>
    <arr name="components">
        <str>suggest</str>
    </arr>
</requestHandler>

4) Copy both fields 'title' and 'content' to 'suggestText' in schema.xml:

<copyField source="title" dest="suggestField"/>
<copyField source="content" dest="suggestField"/>

Questions

Thanks.

Upvotes: 0

Views: 360

Answers (1)

defonion
defonion

Reputation: 121

It seems like you have a typo in your copy-field definition. The "dest" attribute is suggestField but the field you created earlier is called suggestText.

Upvotes: 0

Related Questions