use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testEscapedWildcard.
public void testEscapedWildcard() throws Exception {
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));
WildcardQuery q = new WildcardQuery(new Term("field", "foo\\?ba?r"));
assertEquals(q, getQuery("foo\\?ba?r", qp));
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testPhraseQueryPositionIncrements.
public void testPhraseQueryPositionIncrements() throws Exception {
CharacterRunAutomaton stopStopList = new CharacterRunAutomaton(new RegExp("[sS][tT][oO][pP]").toAutomaton());
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false, stopStopList));
qp.setEnablePositionIncrements(true);
PhraseQuery.Builder phraseQuery = new PhraseQuery.Builder();
phraseQuery.add(new Term("field", "1"));
phraseQuery.add(new Term("field", "2"), 2);
assertEquals(phraseQuery.build(), getQuery("\"1 stop 2\"", qp));
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testLeadingWildcardType.
public void testLeadingWildcardType() throws Exception {
CommonQueryParserConfiguration cqpC = getParserConfig(null);
cqpC.setAllowLeadingWildcard(true);
assertEquals(WildcardQuery.class, getQuery("t*erm*", cqpC).getClass());
assertEquals(WildcardQuery.class, getQuery("?term*", cqpC).getClass());
assertEquals(WildcardQuery.class, getQuery("*term*", cqpC).getClass());
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testParseWildcardAndPhraseQueries.
public void testParseWildcardAndPhraseQueries() throws Exception {
String field = "content";
String oldDefaultField = getDefaultField();
setDefaultField(field);
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random()));
qp.setAllowLeadingWildcard(true);
String[][] prefixQueries = { { "a*", "ab*", "abc*" }, { "h*", "hi*", "hij*", "\\\\7*" }, { "o*", "op*", "opq*", "\\\\\\\\*" } };
String[][] wildcardQueries = { { "*a*", "*ab*", "*abc**", "ab*e*", "*g?", "*f?1", "abc**" }, { "*h*", "*hi*", "*hij**", "hi*k*", "*n?", "*m?1", "hij**" }, { "*o*", "*op*", "*opq**", "op*q*", "*u?", "*t?1", "opq**" } };
// test queries that must be prefix queries
for (int i = 0; i < prefixQueries.length; i++) {
for (int j = 0; j < prefixQueries[i].length; j++) {
String queryString = prefixQueries[i][j];
Query q = getQuery(queryString, qp);
assertEquals(PrefixQuery.class, q.getClass());
}
}
// test queries that must be wildcard queries
for (int i = 0; i < wildcardQueries.length; i++) {
for (int j = 0; j < wildcardQueries[i].length; j++) {
String qtxt = wildcardQueries[i][j];
Query q = getQuery(qtxt, qp);
assertEquals(WildcardQuery.class, q.getClass());
}
}
setDefaultField(oldDefaultField);
}
use of org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration in project lucene-solr by apache.
the class QueryParserTestBase method testPositionIncrement.
public void testPositionIncrement() throws Exception {
CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET));
qp.setEnablePositionIncrements(true);
String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
// 0 2 5 7 8
int[] expectedPositions = { 1, 3, 4, 6, 9 };
PhraseQuery pq = (PhraseQuery) getQuery(qtxt, qp);
//System.out.println("Query text: "+qtxt);
//System.out.println("Result: "+pq);
Term[] t = pq.getTerms();
int[] pos = pq.getPositions();
for (int i = 0; i < t.length; i++) {
//System.out.println(i+". "+t[i]+" pos: "+pos[i]);
assertEquals("term " + i + " = " + t[i] + " has wrong term-position!", expectedPositions[i], pos[i]);
}
}
Aggregations