You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Teague James <te...@insystechinc.com> on 2015/12/01 21:36:55 UTC

Help With Phrase Highlighting

Hello everyone,

I am having difficulty enabling phrase highlighting and am hoping someone
here can offer some help. This is what I have currently:

Solr 4.9
solrconfig.xml (partial snip)
<requestHandler name="/select" class="solr.SearchHandler">
		<lst name="defaults">
			<str name="wt">xml</str>
			<str name="echoParams">explicit</str>
			<int name="rows">10</int>
			<str name="df">text</str>
			<str name="hl">on</str>
			<str name="hl.fl">text</str>
			<str name="hl.encoder">html</str>
			<str name="hl.snippets">100</str>
			<str name="hl.simple.pre"><b></str>
			<str name="hl.simple.post"></b></str>
		</lst>
</requestHandler>

schema.xml (partial snip)
   <field name="id" type="string" indexed="true" stored="true"
required="true" multiValued="false" /> 
   <field name="documentText" type="string" indexed="true" stored="true" />

Query (partial snip):
...select?fq=id:43040&q="my%20search%20phrase"

Response (partial snip):
...
<str>
ipsum dolor sit amet, pro ne verear prompta, sea te aeterno scripta
assentior. (<b>my</b> <b>search</b>
</str>
<str>
<b>phrase</b> facilitates highlighting). Et option molestiae referrentur
ius. Viris quaeque legimus an pri
</str>

The document in which this phrase is found is very long. If I reduce the
document to a single sentence, such as "My search phrase facilitates
highlighting" then the response I get from Solr is:
<str>
<b>My</b> <b>search</b> <b>phrase</b> facilitates highlighting
</str>

What I am trying to achieve instead, regardless of the document size is:
<str><b>My search phrase</b></str> with a single indicator at the beginning
and end rather than three separate words that may get dsitributed between
two different snippets depending on the placement of the snippet in te
larger document.

I tried to follow this guide:
http://stackoverflow.com/questions/25930180/solr-how-to-highlight-the-whole-
search-phrase-only/25970452#25970452 but got zero results. I suspect that
this is due to the hl parameters in my solrconfig file, but I cannot find
any specific guidance on the correct parameters should be. I tried
commenting out all of the hl parameters and also got no results.

Can anyone offer any solutions for searching large documents and returning a
single phrase highlight?

-Teague


RE: Help With Phrase Highlighting

Posted by Teague James <te...@insystechinc.com>.
Thanks everyone who replied! The FastVectorHighlighter did the trick. Here
is how I configured it:

In solrconfig.xml:
In the requestHandler I added:
<str name="hl">on</str>
<str name=hl.fl">text</str>
<str name="hl.useFastVectorHighlighter">true</str>
<str name="hl.snippets">100</str>

In schema.xml:
I modified the text field:
<field name="text" type="text_general" indexed="true" multivalued="true"
termVectors="true" termOffsets="true" termPositions="true" />

I restarted Solr, re-indexed the documents and tested. All phrases are
correctly highlighted as phrases! Thanks everyone!

-Teague


Re: Help With Phrase Highlighting

Posted by Koji Sekiguchi <ko...@rondhuit.com>.
Hi Teague,

I couldn't understand the part of "document size" in your question, but if you'd like
Solr to return snippet

<b>My search phrase</b>

instead of

<b>My</b> <b>search</b> <b>phrase</b>

you should use FastVectorHighlighter. In case use of FVH, your highlight field (hl.fl=text)
need to be indexed with options termVectors=true, termPositions=true and termPositions=true.

Good luck!

Koji


On 2015/12/02 5:36, Teague James wrote:
> Hello everyone,
>
> I am having difficulty enabling phrase highlighting and am hoping someone
> here can offer some help. This is what I have currently:
>
> Solr 4.9
> solrconfig.xml (partial snip)
> <requestHandler name="/select" class="solr.SearchHandler">
> 		<lst name="defaults">
> 			<str name="wt">xml</str>
> 			<str name="echoParams">explicit</str>
> 			<int name="rows">10</int>
> 			<str name="df">text</str>
> 			<str name="hl">on</str>
> 			<str name="hl.fl">text</str>
> 			<str name="hl.encoder">html</str>
> 			<str name="hl.snippets">100</str>
> 			<str name="hl.simple.pre"><b></str>
> 			<str name="hl.simple.post"></b></str>
> 		</lst>
> </requestHandler>
>
> schema.xml (partial snip)
>     <field name="id" type="string" indexed="true" stored="true"
> required="true" multiValued="false" />
>     <field name="documentText" type="string" indexed="true" stored="true" />
>
> Query (partial snip):
> ...select?fq=id:43040&q="my%20search%20phrase"
>
> Response (partial snip):
> ...
> <str>
> ipsum dolor sit amet, pro ne verear prompta, sea te aeterno scripta
> assentior. (<b>my</b> <b>search</b>
> </str>
> <str>
> <b>phrase</b> facilitates highlighting). Et option molestiae referrentur
> ius. Viris quaeque legimus an pri
> </str>
>
> The document in which this phrase is found is very long. If I reduce the
> document to a single sentence, such as "My search phrase facilitates
> highlighting" then the response I get from Solr is:
> <str>
> <b>My</b> <b>search</b> <b>phrase</b> facilitates highlighting
> </str>
>
> What I am trying to achieve instead, regardless of the document size is:
> <str><b>My search phrase</b></str> with a single indicator at the beginning
> and end rather than three separate words that may get dsitributed between
> two different snippets depending on the placement of the snippet in te
> larger document.
>
> I tried to follow this guide:
> http://stackoverflow.com/questions/25930180/solr-how-to-highlight-the-whole-
> search-phrase-only/25970452#25970452 but got zero results. I suspect that
> this is due to the hl parameters in my solrconfig file, but I cannot find
> any specific guidance on the correct parameters should be. I tried
> commenting out all of the hl parameters and also got no results.
>
> Can anyone offer any solutions for searching large documents and returning a
> single phrase highlight?
>
> -Teague
>
>


Re: Help With Phrase Highlighting

Posted by Teague James <te...@insystechinc.com>.
Hello,

Thanks for replying! I tried using it in a query string, but without success. Should I add it to my solrconfig? If so, are there any other hl parameters that are necessary? 

-Teague

> On Dec 1, 2015, at 9:01 PM, Philippe Soares <so...@gqlifesciences.com> wrote:
> 
> Hi,
> Did you try hl.mergeContiguous=true ?
> 
> On Tue, Dec 1, 2015 at 3:36 PM, Teague James <te...@insystechinc.com>
> wrote:
> 
>> Hello everyone,
>> 
>> I am having difficulty enabling phrase highlighting and am hoping someone
>> here can offer some help. This is what I have currently:
>> 
>> Solr 4.9
>> solrconfig.xml (partial snip)
>> <requestHandler name="/select" class="solr.SearchHandler">
>>                <lst name="defaults">
>>                        <str name="wt">xml</str>
>>                        <str name="echoParams">explicit</str>
>>                        <int name="rows">10</int>
>>                        <str name="df">text</str>
>>                        <str name="hl">on</str>
>>                        <str name="hl.fl">text</str>
>>                        <str name="hl.encoder">html</str>
>>                        <str name="hl.snippets">100</str>
>>                        <str name="hl.simple.pre"><b></str>
>>                        <str name="hl.simple.post"></b></str>
>>                </lst>
>> </requestHandler>
>> 
>> schema.xml (partial snip)
>>   <field name="id" type="string" indexed="true" stored="true"
>> required="true" multiValued="false" />
>>   <field name="documentText" type="string" indexed="true" stored="true" />
>> 
>> Query (partial snip):
>> ...select?fq=id:43040&q="my%20search%20phrase"
>> 
>> Response (partial snip):
>> ...
>> <str>
>> ipsum dolor sit amet, pro ne verear prompta, sea te aeterno scripta
>> assentior. (<b>my</b> <b>search</b>
>> </str>
>> <str>
>> <b>phrase</b> facilitates highlighting). Et option molestiae referrentur
>> ius. Viris quaeque legimus an pri
>> </str>
>> 
>> The document in which this phrase is found is very long. If I reduce the
>> document to a single sentence, such as "My search phrase facilitates
>> highlighting" then the response I get from Solr is:
>> <str>
>> <b>My</b> <b>search</b> <b>phrase</b> facilitates highlighting
>> </str>
>> 
>> What I am trying to achieve instead, regardless of the document size is:
>> <str><b>My search phrase</b></str> with a single indicator at the beginning
>> and end rather than three separate words that may get dsitributed between
>> two different snippets depending on the placement of the snippet in te
>> larger document.
>> 
>> I tried to follow this guide:
>> 
>> http://stackoverflow.com/questions/25930180/solr-how-to-highlight-the-whole-
>> search-phrase-only/25970452#25970452 but got zero results. I suspect that
>> this is due to the hl parameters in my solrconfig file, but I cannot find
>> any specific guidance on the correct parameters should be. I tried
>> commenting out all of the hl parameters and also got no results.
>> 
>> Can anyone offer any solutions for searching large documents and returning
>> a
>> single phrase highlight?
>> 
>> -Teague
> 
> 
> -- 
> [image: GQ Life Sciences, Inc.] <http://www.gqlifesciences.com/>Philippe
> Soares Senior Developer   |  [image: ☎] +1 508 599 3963
> GQ Life Sciences, Inc. www.gqlifesciences.comThis email message and any
> attachments are confidential and may be privileged. If you are not the
> intended recipient, please notify GQ Life Sciences immediately by
> forwarding this message to legal@gqlifesciences.com and destroy all copies
> of this message and any attachments without reading or disclosing their
> contents.

Re: Help With Phrase Highlighting

Posted by Philippe Soares <so...@gqlifesciences.com>.
Hi,
Did you try hl.mergeContiguous=true ?

On Tue, Dec 1, 2015 at 3:36 PM, Teague James <te...@insystechinc.com>
wrote:

> Hello everyone,
>
> I am having difficulty enabling phrase highlighting and am hoping someone
> here can offer some help. This is what I have currently:
>
> Solr 4.9
> solrconfig.xml (partial snip)
> <requestHandler name="/select" class="solr.SearchHandler">
>                 <lst name="defaults">
>                         <str name="wt">xml</str>
>                         <str name="echoParams">explicit</str>
>                         <int name="rows">10</int>
>                         <str name="df">text</str>
>                         <str name="hl">on</str>
>                         <str name="hl.fl">text</str>
>                         <str name="hl.encoder">html</str>
>                         <str name="hl.snippets">100</str>
>                         <str name="hl.simple.pre"><b></str>
>                         <str name="hl.simple.post"></b></str>
>                 </lst>
> </requestHandler>
>
> schema.xml (partial snip)
>    <field name="id" type="string" indexed="true" stored="true"
> required="true" multiValued="false" />
>    <field name="documentText" type="string" indexed="true" stored="true" />
>
> Query (partial snip):
> ...select?fq=id:43040&q="my%20search%20phrase"
>
> Response (partial snip):
> ...
> <str>
> ipsum dolor sit amet, pro ne verear prompta, sea te aeterno scripta
> assentior. (<b>my</b> <b>search</b>
> </str>
> <str>
> <b>phrase</b> facilitates highlighting). Et option molestiae referrentur
> ius. Viris quaeque legimus an pri
> </str>
>
> The document in which this phrase is found is very long. If I reduce the
> document to a single sentence, such as "My search phrase facilitates
> highlighting" then the response I get from Solr is:
> <str>
> <b>My</b> <b>search</b> <b>phrase</b> facilitates highlighting
> </str>
>
> What I am trying to achieve instead, regardless of the document size is:
> <str><b>My search phrase</b></str> with a single indicator at the beginning
> and end rather than three separate words that may get dsitributed between
> two different snippets depending on the placement of the snippet in te
> larger document.
>
> I tried to follow this guide:
>
> http://stackoverflow.com/questions/25930180/solr-how-to-highlight-the-whole-
> search-phrase-only/25970452#25970452 but got zero results. I suspect that
> this is due to the hl parameters in my solrconfig file, but I cannot find
> any specific guidance on the correct parameters should be. I tried
> commenting out all of the hl parameters and also got no results.
>
> Can anyone offer any solutions for searching large documents and returning
> a
> single phrase highlight?
>
> -Teague
>
>


-- 
[image: GQ Life Sciences, Inc.] <http://www.gqlifesciences.com/>Philippe
Soares Senior Developer   |  [image: ☎] +1 508 599 3963
GQ Life Sciences, Inc. www.gqlifesciences.comThis email message and any
attachments are confidential and may be privileged. If you are not the
intended recipient, please notify GQ Life Sciences immediately by
forwarding this message to legal@gqlifesciences.com and destroy all copies
of this message and any attachments without reading or disclosing their
contents.