lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Green <eelstretch...@gmail.com>
Subject Highlighting question
Date Tue, 04 Aug 2009 00:05:36 GMT
Hi, folks.  I'm trying to get a very simple example working with Solr
highlighting.  I have a default search field (called, unsurprisingly
"default-search-field") with text in it and I want query terms to be
highlighted in that field when I do a search.

I'm using an up to date (as of this evening) checkout of 1.4.  My
solrconfig.xml contains the following highlighting element:

    <highlighting>
   <!-- Configure the standard fragmenter -->
   <!-- This could most likely be commented out in the "default" case -->
        <fragmenter name="gap"
class="org.apache.solr.highlight.GapFragmenter" default="true">
            <lst name="defaults">
                <int name="hl.fragsize">200</int>
            </lst>
        </fragmenter>

   <!-- A regular-expression-based fragmenter (f.i., for sentence
extraction) -->
        <fragmenter name="regex"
class="org.apache.solr.highlight.RegexFragmenter">
            <lst name="defaults">
      <!-- slightly smaller fragsizes work better because of slop -->
                <int name="hl.fragsize">170</int>
      <!-- allow 50% slop on fragment sizes -->
                <float name="hl.regex.slop">0.5</float>
      <!-- a basic sentence pattern -->
                <str name="hl.regex.pattern">[-\w ,/\n\"']{20,200}</str>
            </lst>
        </fragmenter>

   <!-- Configure the standard formatter -->
        <formatter name="html"
class="org.apache.solr.highlight.HtmlFormatter" default="true">
            <lst name="defaults">
                <str name="hl.simple.pre"><![CDATA[<span class="ht">]]>
                </str>
                <str name="hl.simple.post"><![CDATA[</span>]]>
                </str>
            </lst>
        </formatter>
    </highlighting>

I'm using SolrJ to talk to the Solr server.  Here's the code to do a
query, where qs is the query string.

            SolrQuery q = new SolrQuery(qs);
            q.setQueryType("dismax");
            q.setHighlight(true);
            q.setHighlightFragsize(250);
            q.set("hl.formatter", "html");
            q.set("hl.fragmenter", "regex");
            q.setFields("default-search-field", "key");
            QueryResponse resp = solr.query(q);

I've set up the dismax handler in solrconfig.xml to search the
default-search-field.

The Solr server logs the following request for this:

INFO: [] webapp=/solr path=/select
params={hl.fragsize=250&fl=default-search-field,key&hl.fragmenter=regex&q=garbage&hl.formatter=html&qt=dismax&wt=javabin&hl=true&version=1}
hits=953 status=0 QTime=39

which looks about right to me, but I don't see any highlighting in the results.

I'm clearly missing something pretty fundamental here, and any help
would be appreciated.

Steve Green

Mime
View raw message