Reputation: 365
I am trying to perform a partial search on a field in solr.
my_id: ABC_00123
I would like to search for 123 and see this item. I cannot get it to work without using the my_id field in the query.
In my schema.xml I have put:
<fieldType name="text_ngrm" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="50" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
Then (I'm not sure this is necessary):
<field name="_text_ngrm_" type="text_ngrm" indexed="true" stored="false"/>
I also have:
<field name="my_id" type="text_ngrm" indexed="true" stored="true"/>
Finally:
<copyField source="my_id" dest="_text_ngrm_"/>
For the query this works:
my_id: 223
But 223 on it's own does not. I have the feeling it has to do with this copyField definition.
The only way, I could get it to work was to change:
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
<lst name="defaults">
<str name="df">_text_ngrm_</str>
</lst>
</initParams>
But this breaks all my other default searches. Is there not some way to add like:
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
<lst name="defaults">
<str name="df">_text_</str>
<str name="df">_text_ngrm_</str>
</lst>
</initParams>
Thanks for any help
Upvotes: 0
Views: 37
Reputation: 52912
You can supply the default search field in the URL when querying by providing the df
yourself - so that for your single query, you can supply &df=_text_ngrm_
- since that's the field you want to search.
You can also use the edismax handler to search both - use qf=_text_ _text_ngrm_
- you can also apply different weights to the fields in that case, for example to give more exact hits a higher boost - qf=_text_^5 _text_ngrm_
will give five time higher weight to hits in the _text_
field compared to the _text_ngrm_
field.
Upvotes: 1