Skip to content

Apache Lucene open-source search software

added getTermArrays() and extractTerms() to MultiPhraseQuery: LUCENE-514

Yonik Seeleyfc0d666c814d
diff --git a/CHANGES.txt b/CHANGES.txt
index 32de72fe294..4c45a31b11f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -41,6 +41,10 @@ Bug fixes
8. LUCENE-541: Add missing extractTerms() to DisjunctionMaxQuery
(Stefan Will via Yonik Seeley)
+ 9. LUCENE-514: Added getTermArrays() and extractTerms() to
+ MultiPhraseQuery (Eric Jain & Yonik Seeley)
+
+
1.9.1
Bug fixes
diff --git a/src/java/org/apache/lucene/search/MultiPhraseQuery.java b/src/java/org/apache/lucene/search/MultiPhraseQuery.java
index 17ce727dff7..aa739d45064 100644
--- a/src/java/org/apache/lucene/search/MultiPhraseQuery.java
+++ b/src/java/org/apache/lucene/search/MultiPhraseQuery.java
@@ -17,9 +17,7 @@ package org.apache.lucene.search;
*/
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Vector;
+import java.util.*;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultipleTermPositions;
@@ -97,6 +95,14 @@ public class MultiPhraseQuery extends Query {
positions.addElement(new Integer(position));
}
+ /**
+ * Returns a List<Term[]> of the terms in the multiphrase.
+ * Do not modify the List or it's contents.
+ */
+ public List getTermArrays() {
+ return Collections.unmodifiableList(termArrays);
+ }
+
/**
* Returns the relative positions of terms in this phrase.
*/
@@ -107,6 +113,17 @@ public class MultiPhraseQuery extends Query {
return result;
}
+ // inherit javadoc
+ public void extractTerms(Set terms) {
+ for (Iterator iter = termArrays.iterator(); iter.hasNext();) {
+ Term[] arr = (Term[])iter.next();
+ for (int i=0; i<arr.length; i++) {
+ terms.add(arr[i]);
+ }
+ }
+ }
+
+
private class MultiPhraseWeight implements Weight {
private Similarity similarity;
private float value;