Highlighter problem with SpanNearQuery w/Fix

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Highlighter problem with SpanNearQuery w/Fix

Andrew Boyd
Hi All,
  I have overidden QueryParser's getFieldQuery() so that it returns a SpanNearQuery instead of a PhraseQuery.
 but that stopped the Highlighter working.  I added the following to QueryTermExtractor:

        private static final void getTerms(Query query, HashSet terms,boolean prohibited)
                if (query instanceof BooleanQuery)
                        getTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited);
                        if (query instanceof PhraseQuery)
                                getTermsFromPhraseQuery((PhraseQuery) query, terms);
                                if (query instanceof TermQuery)
                                        getTermsFromTermQuery((TermQuery) query, terms);
                    if(query instanceof SpanNearQuery)  // <<< new <<<<
                        getTermsFromSpanNearQuery((SpanNearQuery) query, terms);

// and

    private static final void getTermsFromSpanNearQuery(SpanNearQuery query, HashSet terms){
        Collection queryTerms = query.getTerms();
        for(Iterator iterator = queryTerms.iterator(); iterator.hasNext();){
            // break it out for debugging.
            Term term = (Term) iterator.next();
            String text = term.text();
            terms.add(new WeightedTerm(query.getBoost(), text));


And that seemed to fix it.

Hope this helps,

Andrew Boyd
Software Architect
Sun Certified J2EE Architect
B&B Technical Services Inc.

To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]