mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
fe6ba518c9
commit
acf8672b4d
|
@ -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<Integer> visited = new HashSet<>();
|
||||
int s = 0;
|
||||
|
|
|
@ -128,6 +128,8 @@ public class TestAutomatonQuery extends LuceneTestCase {
|
|||
BasicAutomata.makeCharLight('a')));
|
||||
}
|
||||
|
||||
// nocommit make a testRandomAutomaton like TestRR2
|
||||
|
||||
/**
|
||||
* Test that a nondeterministic automaton works correctly. (It should will be
|
||||
* determinized)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue