LUCENE-4103: don't try to analyze regexp queries in flexible qp

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1346645 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-06-05 22:57:19 +00:00
parent ddfb21b5d0
commit 5fb2e4a751
3 changed files with 24 additions and 2 deletions

View File

@ -761,8 +761,8 @@ New features
value, custom similarities can now set a integer, float or byte value to the
given Norm object. (Simon Willnauer)
* LUCENE-2604: Added RegexpQuery support to contrib/queryparser.
(Simon Willnauer, Robert Muir)
* LUCENE-2604, LUCENE-4103: Added RegexpQuery support to contrib/queryparser.
(Simon Willnauer, Robert Muir, Daniel Truemper)
* LUCENE-2373: Added a Codec implementation that works with append-only
filesystems (such as e.g. Hadoop DFS). SegmentInfos writing/reading

View File

@ -42,6 +42,7 @@ import org.apache.lucene.queryparser.flexible.core.nodes.TokenizedPhraseQueryNod
import org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorImpl;
import org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
import org.apache.lucene.queryparser.flexible.standard.nodes.MultiPhraseQueryNode;
import org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode;
import org.apache.lucene.queryparser.flexible.standard.nodes.StandardBooleanQueryNode;
import org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode;
@ -106,6 +107,7 @@ public class AnalyzerQueryNodeProcessor extends QueryNodeProcessorImpl {
if (node instanceof TextableQueryNode
&& !(node instanceof WildcardQueryNode)
&& !(node instanceof FuzzyQueryNode)
&& !(node instanceof RegexpQueryNode)
&& !(node.getParent() instanceof RangeQueryNode)) {
FieldQueryNode fieldNode = ((FieldQueryNode) node);

View File

@ -1302,4 +1302,24 @@ public class TestQPHelper extends LuceneTestCase {
dir.close();
}
public void testRegexQueryParsing() throws Exception {
final String[] fields = {"b", "t"};
final StandardQueryParser parser = new StandardQueryParser();
parser.setMultiFields(fields);
parser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
parser.setAnalyzer(new MockAnalyzer(random()));
BooleanQuery exp = new BooleanQuery();
exp.add(new BooleanClause(new RegexpQuery(new Term("b", "ab.+")), BooleanClause.Occur.MUST));
exp.add(new BooleanClause(new RegexpQuery(new Term("t", "ab.+")), BooleanClause.Occur.MUST));
assertEquals(exp, parser.parse("/ab.+/", null));
RegexpQuery regexpQueryexp = new RegexpQuery(new Term("test", "[abc]?[0-9]"));
assertEquals(regexpQueryexp, parser.parse("test:/[abc]?[0-9]/", null));
}
}