Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SOLR copyField directive

Tags:

I have a rather simple SOLR structure, that hold three different fields:

id, text and tags

in the schema.xml I set the following

<uniqueKey>id</uniqueKey> <defaultSearchField>text</defaultSearchField> <solrQueryParser defaultOperator="AND"/> <copyField source="tags" dest="text"/> 

However, when I search a word that only appears as a tag, then the document is not found.

My question here is: does copyField happen before any analyzer runs (index and query) as described here or just before the query analyzer?


EDIT

the analyzer def:

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">     <analyzer type="index">         <tokenizer class="solr.WhitespaceTokenizerFactory" />         <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1" preserveOriginal="1" />         <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />         <filter class="solr.LowerCaseFilterFactory" />                       <filter class="solr.SnowballPorterFilterFactory" language="German" />         <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>     </analyzer>     <analyzer type="query">         <tokenizer class="solr.WhitespaceTokenizerFactory"/>         <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1" preserveOriginal="1" />         <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />         <filter class="solr.LowerCaseFilterFactory" />                       <filter class="solr.SnowballPorterFilterFactory" language="German" />         <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>     </analyzer> </fieldType> 

and the field-type definitions (they are pretty much as the default configs):

<fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/> <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/> 

and last the field definitions:

<fields>     <field name="id" type="string" indexed="true" stored="true" required="true" />     <field name="text" type="text" indexed="true" stored="false" multiValued="true" />     <field name="tags" type="text" indexed="false" stored="false" /> </fields> <uniqueKey>id</uniqueKey> <defaultSearchField>text</defaultSearchField> <solrQueryParser defaultOperator="AND"/> <copyField source="tags" dest="text"/> 
like image 820
harpax Avatar asked Jan 04 '11 16:01

harpax


People also ask

What is copyField in Solr?

copyField uses the matching glob from the source field for the dest field name into which the source content is copied. Copying is done at the stream source level and no copy feeds into another copy. This means that copy fields cannot be chained i.e. you cannot copy from here to there and then from there to elsewhere .

How do I run Solr indexing?

Start the Server If you are running Windows, you can start Solr by running bin\solr. cmd instead. This will start Solr in the background, listening on port 8983. When you start Solr in the background, the script will wait to make sure Solr starts correctly before returning to the command line prompt.

What is dynamic field in Solr?

Dynamic fields allow Solr to index fields that you did not explicitly define in your schema. This is useful if you discover you have forgotten to define one or more fields. Dynamic fields can make your application less brittle by providing some flexibility in the documents you can add to Solr.


1 Answers

The copyField is done when a document is indexed, so it is before the index analyzer. It is really like you had put the same input text in two different fields. But after that, it all depends on the analyzers you defined for both fields.

like image 69
Pascal Dimassimo Avatar answered Sep 28 '22 16:09

Pascal Dimassimo