Reputation: 7871
I am using Solr 6.0
. I want to use the Highlighting
feature of Solr
.
When I make the following query the highlighting
section in the response has only ids (without &hl.q=data:*ad*
) -
http://<hostname>:<port>/solr/<core>/select?q=text:ad&fl=data&rows=10&hl=on&hl.fl=data&hl.preserveMulti=true&hl.mergeContiguous=true
Output -
"highlighting": {
"id1": {},
"id2": {}
}
When I make the following query then I get the desired output (with &hl.q=data:*ad*
) -
http://<hostname>:<port>/solr/<core>/select?q=text:ad&fl=data&rows=10&hl=on&hl.q=data:*ad*&hl.fl=data&hl.preserveMulti=true&hl.mergeContiguous=true
Output -
"highlighting": {
"id1": {
"data": ["<em>advertise</em>",
"<em>add</em>"
]
},
"id2": {
"data": ["<em>admin</em>",
"<em>addon</em>"
]
}
}
Why do I need to pass hl.q? Is there a way to avoid it?
If I want to write a custom requestHandler
(qt)
in solrconfig.xml
then can I pass the q value to hl.q
with *
as prefix and postfix something like hl.q=*$q*
.
I have the following 2 fields -
<field name="text" type="text_suggest" indexed="true" stored="false" multiValued="true"/>
<field name="data" type="lower" indexed="false" stored="true" multiValued="true"/>
Following is the definition of the fields -
<fieldType name="lower" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="30"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
Following is the way data is copied in the 2 fields -
<copyField source="somefield" dest="text" maxChars="30"/>
<copyField source="somefield" dest="data"/>
EDIT 1
When I add &hl.alternateField=data
to the first query then all values in the multi-valued fields show up in the highlighting
section just like a normal search. Like below -
"highlighting": {
"id1": {
"data": ["advertise",
"not relevant",
"add"
]
},
"id2": {
"data": ["admin",
"addon",
"irrelevant"
]
}
}
Upvotes: 0
Views: 852
Reputation: 3752
Add the EdgeNGram filter to the lower type and it will match the first example. It won't match "ad" in data because it doesn't have any NGrams.
Upvotes: 1