From acf8672b4df4a9353db26a827b831917feb72708 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 12 Jun 2014 19:53:15 +0000 Subject: [PATCH] LUCENE-5752: move det to the testcase; clarify javadocs that getCommonPrefix requires det automaton git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5752@1602279 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/util/automaton/SpecialOperations.java | 5 ++--- .../test/org/apache/lucene/search/TestAutomatonQuery.java | 2 ++ .../java/org/apache/solr/parser/SolrQueryParserBase.java | 3 --- .../solr/analysis/TestReversedWildcardFilterFactory.java | 6 ++++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java b/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java index c07e37df523..d4e8abcd25f 100644 --- a/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java +++ b/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java @@ -96,13 +96,12 @@ final public class SpecialOperations { /** * Returns the longest string that is a prefix of all accepted strings and - * visits each state at most once. + * visits each state at most once. The automaton must be deterministic. * * @return common prefix */ - // nocommit a must be det? we should document if so? public static String getCommonPrefix(LightAutomaton a) { - //a.writeDot("cp"); + assert BasicOperations.isDeterministic(a); StringBuilder b = new StringBuilder(); HashSet visited = new HashSet<>(); int s = 0; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java index cc6d6d9a693..9db86b1cf24 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestAutomatonQuery.java @@ -127,6 +127,8 @@ public class TestAutomatonQuery extends LuceneTestCase { assertAutomatonHits(1, BasicOperations.minusLight(BasicAutomata.makeCharRangeLight('a', 'b'), BasicAutomata.makeCharLight('a'))); } + + // nocommit make a testRandomAutomaton like TestRR2 /** * Test that a nondeterministic automaton works correctly. (It should will be diff --git a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java index fe2b16a6aea..f624d70ea77 100644 --- a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java +++ b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java @@ -782,8 +782,6 @@ public abstract class SolrQueryParserBase extends QueryBuilder { if (factory.shouldReverse(termStr)) { automaton = BasicOperations.concatenateLight(automaton, BasicAutomata.makeCharLight(factory.getMarkerChar())); automaton = SpecialOperations.reverse(automaton); - // nocommit why did i have to insert det here? reverse didn't det before - automaton = BasicOperations.determinize(automaton); } else { // reverse wildcardfilter is active: remove false positives // fsa representing false positives (markerChar*) @@ -792,7 +790,6 @@ public abstract class SolrQueryParserBase extends QueryBuilder { BasicAutomata.makeAnyStringLight()); // subtract these away automaton = BasicOperations.minusLight(automaton, falsePositives); - // nocommit and do i need to det here? } return new AutomatonQuery(term, automaton) { // override toString so its completely transparent diff --git a/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java b/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java index 493a6d32951..5de7398ce0a 100644 --- a/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java +++ b/solr/core/src/test/org/apache/solr/analysis/TestReversedWildcardFilterFactory.java @@ -26,6 +26,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.search.AutomatonQuery; import org.apache.lucene.search.Query; +import org.apache.lucene.util.automaton.BasicOperations; import org.apache.lucene.util.automaton.LightAutomaton; import org.apache.lucene.util.automaton.SpecialOperations; import org.apache.solr.SolrTestCaseJ4; @@ -157,10 +158,11 @@ public class TestReversedWildcardFilterFactory extends SolrTestCaseJ4 { /** fragile assert: depends on our implementation, but cleanest way to check for now */ private boolean wasReversed(SolrQueryParser qp, String query) throws Exception { Query q = qp.parse(query); - if (!(q instanceof AutomatonQuery)) + if (!(q instanceof AutomatonQuery)) { return false; + } LightAutomaton automaton = ((AutomatonQuery) q).getLightAutomaton(); - String prefix = SpecialOperations.getCommonPrefix(automaton); + String prefix = SpecialOperations.getCommonPrefix(BasicOperations.determinize(automaton)); return prefix.length() > 0 && prefix.charAt(0) == '\u0001'; }