Michiel van Oosterhout
Michiel van Oosterhout

Reputation: 23084

In Solr, is it possible to add values for document during indexing, based on a certain field value and a lookup?

Given a text file of unique values, is there an analyzer configuration possible that would use a field of a document that is to be indexed and look it up in the text file, and when found, add a value to another field?

Scenario: products with a unique ID are being indexed, if a product's ID is found in special.txt, then the field 'special' is set to true.

This is for adding occasional information to an index from a manually maintained external data source.

Upvotes: 1

Views: 98

Answers (2)

Alexandre Ouicher
Alexandre Ouicher

Reputation: 856

You can use a transformer in your dataconfig

<dataConfig>
    <script><![CDATA[
            function checkProductID(row)    {
                if(row.get('ProducID') !== NULL)
                {
                    row.put('special', 1);
                }
                return row;
            }
    ]]></script>
    <document>
            <entity name="e" pk="id" transformer="checkProductID">
            ....
            </entity>
    </document>
</dataConfig>

The new field (special) must be in schema.xml

Upvotes: 0

Jayendra
Jayendra

Reputation: 52779

Nope. but you can try for options

  1. Create a New Filter/Analyzer and use it with copyfield with source as product id. Load the file, if a match found add special as the token in the copyfield dest.
  2. Use synonyms text with id=special mapping so that field match if found would have special as the contents.
  3. If using DIH check for ScriptTransformer which will allow you to check value and add a new field

Upvotes: 1

Related Questions