Solr: how to highlight an entire search phrase?

A I need to search for a phrase. In the search results I'm getting exact word matches, but looking at the highlighted parts I see that the phrase is denoted ie This is what I get when I search for prase "Day 1":

<arr name="post">
  <str><em>Day</em> <em>1</em>   We have begun a new adventure! An early morning (4:30 a.m.) has found me meeting with</str>
</arr>

      

This is what I want as a result:

    <arr name="post">
  <str><em>Day 1</em>   We have begun a new adventure! An early morning (4:30 a.m.) has found me meeting with</str>
</arr>

      

The request I'm making is this: Admin Console:

q = day 1 
fq = post:"day 1" OR title:"day 1"
hl = true
hl.fl =title,post

      

choose Q = day + 1 &? FQ = message% 3A% 22day + -% 22 + or + name% 3A% 22day + -% 22 & amp; weight = XML & amp; indent = true & amp; glo = true & amp; hl.fl = title% 2Cpost & hl.simple.pre =% 3Cem% 3E & hl.simple.post =% 3C% 3E% 2Fem

These are my fields:

     <field name="post" type="text_general" indexed="true" stored="true" required="true" multiValued="false" />
      <field name="post" type="text_general" indexed="true" stored="true" required="true" multiValued="false" />

      

This is the solr schema section for my text_general fied type:

    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />

    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.GreekStemFilterFactory"/>
    <filter class="solr.GreekLowerCaseFilterFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

      

B) I see more disturbing results in the highlighted section, highlighting not the whole word as expected, but single fragments: .where you get to see all of Athens ... <em>Day</em> 2 - Carmens

I do not want to see this result in the highlighted section (you only need to see both words "Day 1"). Any ideas?

I'm reading the Solr highlighting section but .. really ... not even 1 example !!!

+3


source to share


2 answers


The parameter that needed to be inserted was hl.q

which basically means "I want this phrase to be highlighted" and hl.usePhraseHighlighter = true and hl.useFastVectorHighlighter = true

So, adding to my original query: &hl.q="Day+1"&hl.usePhraseHighlighter=true&hl.useFastVectorHighlighter=true

worked.

for B) I changed fq = post:"day 1" OR title:"day 1"

to fq = post:"day 1"

. I know the last less of what I need never works.



the fastVectorHighliter config that was used:

   <field name="post" type="text_general" indexed="true" stored="true" required="true" multiValued="false"  termVectors="true" termPositions="true" termOffsets="true"/>

      

+6


source


Looking at the docs I found an option to connect selection for items that are next to each other.



Option hl.mergeContiguous

+1


source







All Articles