I'm currently using this snippet (with older Highlighter): HitPositionCollector collector = new HitPositionCollector(); highlighter = new Highlighter(collector, scorer); highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer, Integer.MAX_VALUE)); TokenStream stream = TokenSources.getAnyTokenStream(isearcher.getIndexReader(), docs[i].doc, FIELD_CONTENTS, hitDoc, analyzer); String fragment = highlighter.getBestFragment(stream, content); ArrayList<MatchOffset> list = collector.getMatchList();
public static class HitPositionCollector implements Formatter{ // MatchOffset is a simple DTO private ArrayList<MatchOffset> matchList; public HitPositionCollector(){ matchList= new ArrayList<MatchOffset>(); } // this ie where the term start and end offset as well as the actual term is captured @Override public String highlightTerm(String originalText, TokenGroup tokenGroup) { if (tokenGroup.getTotalScore() <= 0) { } else{ MatchOffset mo= new MatchOffset(tokenGroup.getToken(0).toString(), tokenGroup.getStartOffset(),tokenGroup.getEndOffset()); getMatchList().add(mo); } return originalText; } /** * @return the matchList */ public ArrayList<MatchOffset> getMatchList() { return matchList; } //----------------------------------------------------------------------------------------------------- // // Inner classes // //----------------------------------------------------------------------------------------------------- public static class MatchOffset { public String smth; public int start; public int end; public MatchOffset(String smth, int start, int end) { this.smth = smth; this.start = start; this.end = end; } } } The solution with PostingsHighlighter is similar to this? I mean here I have custom Formatter and I need a custom one for PostingHighlighter too? -- View this message in context: http://lucene.472066.n3.nabble.com/How-to-get-hits-coordinates-in-Lucene-4-4-0-tp4083913p4084233.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org