Search in sources :

Example 31 with RegexpQuery

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());
}
Also used : SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) Test(org.junit.Test)

Example 32 with RegexpQuery

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());
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanExpansionQuery(de.ids_mannheim.korap.query.SpanExpansionQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) RegexpQuery(org.apache.lucene.search.RegexpQuery) Test(org.junit.Test)

Example 33 with RegexpQuery

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());
}
Also used : SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanExpansionQuery(de.ids_mannheim.korap.query.SpanExpansionQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) RegexpQuery(org.apache.lucene.search.RegexpQuery) Test(org.junit.Test)

Example 34 with RegexpQuery

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;
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) Term(org.apache.lucene.index.Term) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 35 with RegexpQuery

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));
    }
}
Also used : CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Aggregations

RegexpQuery (org.apache.lucene.search.RegexpQuery)35 Term (org.apache.lucene.index.Term)30 PrefixQuery (org.apache.lucene.search.PrefixQuery)9 WildcardQuery (org.apache.lucene.search.WildcardQuery)9 BooleanQuery (org.apache.lucene.search.BooleanQuery)8 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)8 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)8 Test (org.junit.Test)7 KrillIndex (de.ids_mannheim.korap.KrillIndex)6 Query (org.apache.lucene.search.Query)6 TermQuery (org.apache.lucene.search.TermQuery)6 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)5 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)5 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)4 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)4 Document (org.apache.lucene.document.Document)4 IntPoint (org.apache.lucene.document.IntPoint)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)4 SpanQuery (org.apache.lucene.search.spans.SpanQuery)4