lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Boyd <>
Subject Highlighter problem with SpanNearQuery w/Fix
Date Tue, 14 Jun 2005 19:57:38 GMT
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);
            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:
For additional commands, e-mail:

View raw message