use of org.apache.lucene.search.RegexpQuery in project Krill by KorAP.
the class TestRegexIndex method testWildcardStarRewritten.
@Test
public void testWildcardStarRewritten() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// meine* /+w1:2,s0 &Erfahrung
// rewritten into meine.*
RegexpQuery wcquery = new RegexpQuery(new Term("tokens", "s:meine.*"));
SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(wcquery);
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(4, kr.getMatches().size());
}
use of org.apache.lucene.search.RegexpQuery in project Krill by KorAP.
the class TestSpanExpansionIndex method testQueryRewriteBug.
/**
* Query rewrite bug
*
* Warning: This is not armoured by <base/s=t>!
*
* @throws IOException
*/
@Test
public void testQueryRewriteBug() throws IOException {
KrillIndex ki = new KrillIndex();
// ceccecdeec
ki.addDoc(createFieldDoc0());
/*
ki.addDoc(createFieldDoc1()); // bbccdd || only not clause
ki.addDoc(createFieldDoc2()); // beccea | only main clause
*/
ki.commit();
// See /queries/bugs/repetition_group_rewrite
RegexpQuery requery = new RegexpQuery(new Term("base", "s:[ac]"), RegExp.ALL);
SpanMultiTermQueryWrapper<RegexpQuery> query = new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
SpanExpansionQuery seq = new SpanExpansionQuery(query, 1, 1, 1, true);
SpanRepetitionQuery rep = new SpanRepetitionQuery(seq, 2, 2, true);
// spanRepetition(
// spanExpansion(
// SpanMultiTermQueryWrapper(base:/s:[ac]/),
// []{1, 1},
// right
// ){2,2}
// )
kr = ki.search(query, (short) 20);
assertEquals(5, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(1, kr.getMatch(0).getEndPos());
assertEquals(2, kr.getMatch(1).getStartPos());
assertEquals(3, kr.getMatch(1).getEndPos());
assertEquals(3, kr.getMatch(2).getStartPos());
assertEquals(4, kr.getMatch(2).getEndPos());
assertEquals(5, kr.getMatch(3).getStartPos());
assertEquals(6, kr.getMatch(3).getEndPos());
assertEquals(9, kr.getMatch(4).getStartPos());
assertEquals(10, kr.getMatch(4).getEndPos());
kr = ki.search(seq, (short) 20);
assertEquals(5, kr.getTotalResults());
assertEquals(0, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
assertEquals(2, kr.getMatch(1).getStartPos());
assertEquals(4, kr.getMatch(1).getEndPos());
assertEquals(3, kr.getMatch(2).getStartPos());
assertEquals(5, kr.getMatch(2).getEndPos());
assertEquals(5, kr.getMatch(3).getStartPos());
assertEquals(7, kr.getMatch(3).getEndPos());
assertEquals(9, kr.getMatch(4).getStartPos());
assertEquals(11, kr.getMatch(4).getEndPos());
kr = ki.search(rep, (short) 20);
assertEquals("[[cecc]]ecdeec", kr.getMatch(0).getSnippetBrackets());
assertEquals("cec[[cecd]]eec", kr.getMatch(1).getSnippetBrackets());
assertEquals((long) 2, kr.getTotalResults());
}
use of org.apache.lucene.search.RegexpQuery in project Krill by KorAP.
the class TestSpanExpansionIndex method testBugRegexExpandLeftNoMoreSpan.
@Test
public void testBugRegexExpandLeftNoMoreSpan() throws IOException {
KrillIndex ki = new KrillIndex();
ki.addDoc(createFieldDoc6());
ki.commit();
SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:a"));
RegexpQuery requery = new RegexpQuery(new Term("base", "s:[bc]"), RegExp.ALL);
SpanMultiTermQueryWrapper<RegexpQuery> notQuery = new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
byte classNumber = 1;
// left expansion
SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 0, 1, -1, classNumber, true);
kr = ki.search(seq, (short) 20);
assertEquals(9, kr.getMatches().size());
}
use of org.apache.lucene.search.RegexpQuery in project kie-wb-common by kiegroup.
the class AbstractQueryBuilder method getQuery.
public Query getQuery(ValueIndexTerm valueTerm) {
final String text = getText(valueTerm);
Term term = new Term(valueTerm.getTerm(), text);
Query termQuery;
switch(valueTerm.getSearchType()) {
case PREFIX:
termQuery = new PrefixQuery(term);
break;
case WILDCARD:
termQuery = new WildcardQuery(term);
break;
case REGEXP:
// NONE until there's a specific reason to use extend regex syntax
termQuery = new RegexpQuery(term, RegExp.NONE);
break;
case NORMAL:
termQuery = new TermQuery(term);
break;
default:
throw new UnsupportedOperationException(ValueIndexTerm.TermSearchType.class.getSimpleName() + " value " + valueTerm.getSearchType().toString() + " is unsupported!");
}
return termQuery;
}
use of org.apache.lucene.search.RegexpQuery in project crate by crate.
the class RegexpMatchOperator method toQuery.
@Override
public Query toQuery(Reference ref, Literal<?> literal, Context context) {
String pattern = (String) literal.value();
Term term = new Term(ref.column().fqn(), pattern);
if (RegexpFlags.isPcrePattern(pattern)) {
return new CrateRegexQuery(term);
} else {
return new ConstantScoreQuery(new RegexpQuery(term, RegExp.ALL));
}
}
Aggregations