Pregunta

I am trying to map my category ids to their names in Solr, to allow for text searching using that category name

My plan was to use a custom fieldType specification, which uses the MappingCharFilterFactory to map my ids to their categories, using a synonyms.txt file. After the mapping, the rest is just a standard tokenizer and lowercase filter

While this is working as expected for indexing (i.e. searching works), my results still contain the ids, instead of their names.

Does anyone know what I am doing wrong? Or if there's a better way of achieving the same results?

Thx for any help


Field Definitions

<field name="q_category_id" type="string" indexed="true" stored="true" multiValued="true" />
<field name="q_category_name" type="text_category" indexed="true" stored="true" multiValued="true" />
<copyField source="q_category_id" dest="q_category_name" />

FieldType Definitions

<fieldType name="text_category" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <charFilter class="solr.MappingCharFilterFactory" mapping="synonyms.txt"/>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <charFilter class="solr.MappingCharFilterFactory" mapping="synonyms.txt"/>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

Synonyms.txt

...
"14" => "Music"
"16" => "Science"
"17" => "Sports & Games"
"18" => "Technology & Manufacturing"
...
¿Fue útil?

Solución

Solr does not change the Actual stored values which is returned with Response. It will only update the indexed value.
That is why your searches would work on the Indexed value. However, the response returned by Solr will always have the stored value.
You would need to handle the change at the client side for Solr to return it with Response.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top