lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AarKay <ksu.wildc...@gmail.com>
Subject FastVectorHighlighter returns null fragments - Lucene 4.0
Date Thu, 09 May 2013 14:30:27 GMT
I have an index built using Lucene4 with below config
storeTermVectors=true
storeTermVectorPositions=true
storeTermVectorOffsets=true
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS

I am trying to use FastVectorHighlighter for retrieving the snippets from
hit docs but getBestFragment method is returning nulls even when there are
hit docs.

Can someone please tell me what am i doing wrong?

Here is the code snippet on how I am using FastVectorHighlighter

    private FastVectorHighlighter getHighlighter() {
        FragListBuilder fragListBuilder = new SimpleFragListBuilder(200);
        FragmentsBuilder fragmentBuilder = new
SimpleFragmentsBuilder(PRE_TAGS, POST_TAGS);
        return new FastVectorHighlighter(true, true, fragListBuilder,
fragmentBuilder);
    }

    public void testHighlight(String term) throws Exception {
    ClassicAnalyzer analyzer = new ClassicAnalyzer(Version.LUCENE_40);
        Query query = new QueryParser(Version.LUCENE_40, "contents:,
analyzer).parse(term);
        FastVectorHighlighter highlighter = getHighlighter();
        FieldQuery fieldQuery = highlighter.getFieldQuery(query);

        TopDocs topDocs = indexSearcher.search(query, 10);
        List<String> fragments = new ArrayList<String>();
        for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
            fragments.add(highlighter.getBestFragment(fieldQuery,
indexSearcher.getIndexReader(), scoreDoc.doc, "contents", 1000));
        }

        System.out.println( fragments.size() + " " + fragments.toString());
    }


Thanks
AarKay

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message