You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2013/02/24 22:46:41 UTC
svn commit: r1449554 - in /lucene/dev/branches/LUCENE-2878/lucene/core/src:
java/org/apache/lucene/search/posfilter/ExactMultiPhraseQuery.java
test/org/apache/lucene/search/posfilter/TestExactPhraseQuery.java
Author: romseygeek
Date: Sun Feb 24 21:46:40 2013
New Revision: 1449554
URL: http://svn.apache.org/r1449554
Log:
Add ExactMultiPhraseQuery based on PositionFilteredQuery
Added:
lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/posfilter/ExactMultiPhraseQuery.java (with props)
Modified:
lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestExactPhraseQuery.java
Added: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/posfilter/ExactMultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/posfilter/ExactMultiPhraseQuery.java?rev=1449554&view=auto
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/posfilter/ExactMultiPhraseQuery.java (added)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/posfilter/ExactMultiPhraseQuery.java Sun Feb 24 21:46:40 2013
@@ -0,0 +1,60 @@
+package org.apache.lucene.search.posfilter;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.TermQuery;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class ExactMultiPhraseQuery extends PositionFilterQuery {
+
+ private final BooleanQuery innerBQ;
+
+ public ExactMultiPhraseQuery() {
+ super(new BooleanQuery(), new ExactMultiPhraseScorerFactory());
+ this.innerBQ = (BooleanQuery) innerQuery;
+ }
+
+ public void add(Term term) {
+ innerBQ.add(new TermQuery(term), BooleanClause.Occur.MUST);
+ }
+
+ public void add(Term... terms) {
+ BooleanQuery disj = new BooleanQuery();
+ for (Term term : terms) {
+ disj.add(new TermQuery(term), BooleanClause.Occur.SHOULD);
+ }
+ innerBQ.add(disj, BooleanClause.Occur.MUST);
+ }
+
+ private static class ExactMultiPhraseScorerFactory implements ScorerFilterFactory {
+
+ @Override
+ public Scorer scorer(Scorer filteredScorer) {
+ return new BlockPhraseScorer(filteredScorer);
+ }
+
+ @Override
+ public String getName() {
+ return "ExactMultiPhrase";
+ }
+ }
+
+}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestExactPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestExactPhraseQuery.java?rev=1449554&r1=1449553&r2=1449554&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestExactPhraseQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestExactPhraseQuery.java Sun Feb 24 21:46:40 2013
@@ -19,12 +19,6 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.intervals.BlockIntervalFilter;
-import org.apache.lucene.search.intervals.IntervalFilterQuery;
import java.io.IOException;
@@ -60,6 +54,19 @@ public class TestExactPhraseQuery extend
}
}
+ public void testMultiPhrases() throws IOException {
+
+ ExactMultiPhraseQuery q = new ExactMultiPhraseQuery();
+ q.add(new Term("field", "pease"));
+ q.add(new Term("field", "porridge"));
+ q.add(new Term("field", "hot!"), new Term("field", "cold!"));
+
+ checkIntervals(q, searcher, new int[][]{
+ { 0, 0, 2, 3, 5, 31, 33, 34, 36 },
+ { 1, 0, 2, 3, 5, 31, 33, 34, 36 }
+ });
+ }
+
public void testOverlaps() throws IOException {
ExactPhraseQuery q = new ExactPhraseQuery();
q.add(new Term("field", "some"));
@@ -106,16 +113,11 @@ public class TestExactPhraseQuery extend
public void testNonMatching() throws IOException {
- BooleanQuery query = new BooleanQuery();
- query.add(new BooleanClause(new TermQuery(new Term("field", "pease")), Occur.MUST));
- query.add(new BooleanClause(new TermQuery(new Term("field", "hot!")), Occur.MUST));
- IntervalFilterQuery filterQuery = new IntervalFilterQuery(query, new BlockIntervalFilter());
-
ExactPhraseQuery q = new ExactPhraseQuery();
q.add(new Term("field", "pease"));
q.add(new Term("field", "hot!"));
- checkIntervals(filterQuery, searcher, new int[][]{});
+ checkIntervals(q, searcher, new int[][]{});
}