Search in sources :

Example 71 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project drools-wb by kiegroup.

the class IndexRuleAttributeNameAndValueTest method testIndexDrlRuleAttributeNameAndValues.

@Test
public void testIndexDrlRuleAttributeNameAndValues() throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("drl1.rdrl");
    final String drl = loadText("drl1.rdrl");
    ioService().write(path, drl);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
        ValueSharedPartIndexTerm indexTerm = new ValueSharedPartIndexTerm("*", PartType.RULEFLOW_GROUP);
        queryBuilder.add(new WildcardQuery(new Term(indexTerm.getTerm(), indexTerm.getValue())), BooleanClause.Occur.MUST);
        queryBuilder.add(new WildcardQuery(new Term("shared:nonexistend", "*")), BooleanClause.Occur.MUST);
        searchFor(index, queryBuilder.build(), 0);
    }
    {
        // This could also just be a TermQuery..
        final BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
        ValueSharedPartIndexTerm indexTerm = new ValueSharedPartIndexTerm("myruleflowgroup", PartType.RULEFLOW_GROUP);
        queryBuilder.add(new TermQuery(new Term(indexTerm.getTerm(), indexTerm.getValue())), BooleanClause.Occur.MUST);
        searchFor(index, queryBuilder.build(), 1);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) BooleanQuery(org.apache.lucene.search.BooleanQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Aggregations

WildcardQuery (org.apache.lucene.search.WildcardQuery)71 Term (org.apache.lucene.index.Term)63 BooleanQuery (org.apache.lucene.search.BooleanQuery)30 PrefixQuery (org.apache.lucene.search.PrefixQuery)24 Query (org.apache.lucene.search.Query)22 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)20 TermQuery (org.apache.lucene.search.TermQuery)20 Document (org.apache.lucene.document.Document)17 BoostQuery (org.apache.lucene.search.BoostQuery)15 IndexSearcher (org.apache.lucene.search.IndexSearcher)15 RegexpQuery (org.apache.lucene.search.RegexpQuery)15 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 PhraseQuery (org.apache.lucene.search.PhraseQuery)14 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)14 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)14 Field (org.apache.lucene.document.Field)13 IndexReader (org.apache.lucene.index.IndexReader)13 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)13 TopDocs (org.apache.lucene.search.TopDocs)13 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)13