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 Petr Gola <go...@effectiva.cz> on 2009/04/08 17:33:16 UTC

Highlighting not stored fields

Hi everyone,

I'm excited with Solr. It is exactly what we wanted to write by ourself 
some time ago. We've already started but now we want to use Solr because 
of many solved "enterprise" features. I have to say It is great project! 
I've downloaded Solr 1.3 + SolrJ and have tried to use as embedded one. 
Everything works fine but one thing is missing - or I can not find it.

In pure Lucene, I can do highlighting after searching. Field values are 
not stored so I fetch these from database and make highlighting.
In Solr, I can't find similar feature. I can do highlighting only on 
STORED fields during query like this:

            SolrQuery query = new SolrQuery()
                    .setQuery(queryString)
                    .addField(IFIELD_SCORE)
                    .addHighlightField(IFIELD_TITLE)
                    .addHighlightField(IFIELD_CONTENT)
                    .addHighlightField(IFIELD_SUBJECT)
                    .setHighlight(true)
                    .setHighlightFragsize(100)
                    .setHighlightSnippets(1)
                    .setHighlightSimplePre("<b>")
                    .setHighlightSimplePost("</b>");
            QueryResponse response = solrServer.query(query);
            Map<String, Map<String, List<String>>> highlighting = 
response.getHighlighting();

If the fields is NOT STORED, highlighting does not work (it is logical 
but there is no way to provide field values for highlighting)

But I want to do something like this (I've used this in pure Lucene):

    Query queryRewrited = query.rewrite(indexSearcher.getIndexReader());
    QueryScorer framgmentScorer = new QueryScorer(queryRewrited);
    SimpleHTMLEncoder simpleHTMLEncoder = new SimpleHTMLEncoder();
    SimpleHTMLFormatter simpleHTMLFormatter = new 
SimpleHTMLFormatter("<span class='highlight'>", "</span>");
    Highlighter highlighter = new Highlighter(simpleHTMLFormatter, 
simpleHTMLEncoder, framgmentScorer);
    highlighter.setTextFragmenter(new NullFragmenter());
...
    private String doHighlight(String content, String fieldId, 
Highlighter highlighter) {
        String hlContent = content;
        hlContent = highlighter.getBestFragment(analyzer, fieldId, 
hlContent);
        return hlContent;
    }

Is there any way to do this? I've googled it for last two nights... I 
haven't found way in to retreive
    1) rewrited Query
    2) QueryScorer
    3) Solr field type and their Analyzers (both, index+query)

Thanks in advance.

Petr





Re: Highlighting not stored fields

Posted by Petr Gola <go...@effectiva.cz>.
Yes, it is interesting one because I'm going to create multilingual 
index! :) Thanks a lot.

It leads me to new idea - what about creating new service (request 
handler) of type "do-highlight" (instead of "do-search"). Adding 
something like HighlightRequest to Solr API and 
SolrServer.highlight(HighlightRequest req) Solr Server API. Maybe, there 
is not the right place for these suggestions :)

However I'm still looking for easier and faster solution...


Petr


Erik Hatcher wrote:
> Peter - interestingly, a related issue was opened not long before you 
> asked this question:  http://issues.apache.org/jira/browse/SOLR-1105 - 
> not quite what you're looking for, but getting warmer.
>
>     Erik
>
>
> On Apr 8, 2009, at 11:33 AM, Petr Gola wrote:
>
>> Hi everyone,
>>
>> I'm excited with Solr. It is exactly what we wanted to write by 
>> ourself some time ago. We've already started but now we want to use 
>> Solr because of many solved "enterprise" features. I have to say It 
>> is great project! I've downloaded Solr 1.3 + SolrJ and have tried to 
>> use as embedded one. Everything works fine but one thing is missing - 
>> or I can not find it.
>>
>> In pure Lucene, I can do highlighting after searching. Field values 
>> are not stored so I fetch these from database and make highlighting.
>> In Solr, I can't find similar feature. I can do highlighting only on 
>> STORED fields during query like this:
>>
>>           SolrQuery query = new SolrQuery()
>>                   .setQuery(queryString)
>>                   .addField(IFIELD_SCORE)
>>                   .addHighlightField(IFIELD_TITLE)
>>                   .addHighlightField(IFIELD_CONTENT)
>>                   .addHighlightField(IFIELD_SUBJECT)
>>                   .setHighlight(true)
>>                   .setHighlightFragsize(100)
>>                   .setHighlightSnippets(1)
>>                   .setHighlightSimplePre("<b>")
>>                   .setHighlightSimplePost("</b>");
>>           QueryResponse response = solrServer.query(query);
>>           Map<String, Map<String, List<String>>> highlighting = 
>> response.getHighlighting();
>>
>> If the fields is NOT STORED, highlighting does not work (it is 
>> logical but there is no way to provide field values for highlighting)
>>
>> But I want to do something like this (I've used this in pure Lucene):
>>
>>   Query queryRewrited = query.rewrite(indexSearcher.getIndexReader());
>>   QueryScorer framgmentScorer = new QueryScorer(queryRewrited);
>>   SimpleHTMLEncoder simpleHTMLEncoder = new SimpleHTMLEncoder();
>>   SimpleHTMLFormatter simpleHTMLFormatter = new 
>> SimpleHTMLFormatter("<span class='highlight'>", "</span>");
>>   Highlighter highlighter = new Highlighter(simpleHTMLFormatter, 
>> simpleHTMLEncoder, framgmentScorer);
>>   highlighter.setTextFragmenter(new NullFragmenter());
>> ...
>>   private String doHighlight(String content, String fieldId, 
>> Highlighter highlighter) {
>>       String hlContent = content;
>>       hlContent = highlighter.getBestFragment(analyzer, fieldId, 
>> hlContent);
>>       return hlContent;
>>   }
>>
>> Is there any way to do this? I've googled it for last two nights... I 
>> haven't found way in to retreive
>>   1) rewrited Query
>>   2) QueryScorer
>>   3) Solr field type and their Analyzers (both, index+query)
>>
>> Thanks in advance.
>>
>> Petr
>>
>>
>>
>


Re: Highlighting not stored fields

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Peter - interestingly, a related issue was opened not long before you  
asked this question:  http://issues.apache.org/jira/browse/SOLR-1105 -  
not quite what you're looking for, but getting warmer.

	Erik


On Apr 8, 2009, at 11:33 AM, Petr Gola wrote:

> Hi everyone,
>
> I'm excited with Solr. It is exactly what we wanted to write by  
> ourself some time ago. We've already started but now we want to use  
> Solr because of many solved "enterprise" features. I have to say It  
> is great project! I've downloaded Solr 1.3 + SolrJ and have tried to  
> use as embedded one. Everything works fine but one thing is missing  
> - or I can not find it.
>
> In pure Lucene, I can do highlighting after searching. Field values  
> are not stored so I fetch these from database and make highlighting.
> In Solr, I can't find similar feature. I can do highlighting only on  
> STORED fields during query like this:
>
>           SolrQuery query = new SolrQuery()
>                   .setQuery(queryString)
>                   .addField(IFIELD_SCORE)
>                   .addHighlightField(IFIELD_TITLE)
>                   .addHighlightField(IFIELD_CONTENT)
>                   .addHighlightField(IFIELD_SUBJECT)
>                   .setHighlight(true)
>                   .setHighlightFragsize(100)
>                   .setHighlightSnippets(1)
>                   .setHighlightSimplePre("<b>")
>                   .setHighlightSimplePost("</b>");
>           QueryResponse response = solrServer.query(query);
>           Map<String, Map<String, List<String>>> highlighting =  
> response.getHighlighting();
>
> If the fields is NOT STORED, highlighting does not work (it is  
> logical but there is no way to provide field values for highlighting)
>
> But I want to do something like this (I've used this in pure Lucene):
>
>   Query queryRewrited = query.rewrite(indexSearcher.getIndexReader());
>   QueryScorer framgmentScorer = new QueryScorer(queryRewrited);
>   SimpleHTMLEncoder simpleHTMLEncoder = new SimpleHTMLEncoder();
>   SimpleHTMLFormatter simpleHTMLFormatter = new  
> SimpleHTMLFormatter("<span class='highlight'>", "</span>");
>   Highlighter highlighter = new Highlighter(simpleHTMLFormatter,  
> simpleHTMLEncoder, framgmentScorer);
>   highlighter.setTextFragmenter(new NullFragmenter());
> ...
>   private String doHighlight(String content, String fieldId,  
> Highlighter highlighter) {
>       String hlContent = content;
>       hlContent = highlighter.getBestFragment(analyzer, fieldId,  
> hlContent);
>       return hlContent;
>   }
>
> Is there any way to do this? I've googled it for last two nights...  
> I haven't found way in to retreive
>   1) rewrited Query
>   2) QueryScorer
>   3) Solr field type and their Analyzers (both, index+query)
>
> Thanks in advance.
>
> Petr
>
>
>