You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mh...@apache.org on 2005/06/30 22:09:59 UTC

svn commit: r208673 - /lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java

Author: mharwood
Date: Thu Jun 30 13:09:58 2005
New Revision: 208673

URL: http://svn.apache.org/viewcvs?rev=208673&view=rev
Log:
Added (simple) SpanQuery support - matches any terms declared in Spans - proper impl should check for distances

Modified:
    lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java

Modified: lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java?rev=208673&r1=208672&r2=208673&view=diff
==============================================================================
--- lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java (original)
+++ lucene/java/trunk/contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java Thu Jun 30 13:09:58 2005
@@ -16,7 +16,9 @@
  */
 
 import java.io.IOException;
+import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
@@ -25,6 +27,7 @@
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.spans.SpanNearQuery;
 
 /**
  * Utility class used to extract the terms used in a query, plus any weights.
@@ -101,15 +104,9 @@
 			else
 				if (query instanceof TermQuery)
 					getTermsFromTermQuery((TermQuery) query, terms);
-//				else
-//					if ((query instanceof PrefixQuery)
-//						|| (query instanceof RangeQuery)
-//						|| (query instanceof MultiTermQuery))
-//					{
-//						//client should call rewrite BEFORE calling highlighter
-//						//						Query expandedQuery = rewrite(reader, query);
-//						//				getTerms(reader, expandedQuery, terms, prohibited);
-//					}
+				else
+		        if(query instanceof SpanNearQuery)
+		            getTermsFromSpanNearQuery((SpanNearQuery) query, terms);
 	}
 
 	private static final void getTermsFromBooleanQuery(BooleanQuery query, HashSet terms, boolean prohibited)
@@ -140,5 +137,24 @@
 		terms.add(new WeightedTerm(query.getBoost(),query.getTerm().text()));
 	}
 
+    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));
+
+ 
+
+        }
+
+    }
 
 }