Search in sources :

Example 1 with QueryNodeProcessorPipeline

use of org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorPipeline in project lucene-solr by apache.

the class TestSpanQueryParser method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    this.spanProcessorPipeline = new QueryNodeProcessorPipeline();
    this.spanQueryConfigHandler = new SpansQueryConfigHandler();
    this.spansQueryTreeBuilder = new SpansQueryTreeBuilder();
    // set up the processor pipeline
    this.spanProcessorPipeline.setQueryConfigHandler(this.spanQueryConfigHandler);
    this.spanProcessorPipeline.add(new WildcardQueryNodeProcessor());
    this.spanProcessorPipeline.add(new SpansValidatorQueryNodeProcessor());
    this.spanProcessorPipeline.add(new UniqueFieldQueryNodeProcessor());
}
Also used : WildcardQueryNodeProcessor(org.apache.lucene.queryparser.flexible.standard.processors.WildcardQueryNodeProcessor) QueryNodeProcessorPipeline(org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorPipeline)

Example 2 with QueryNodeProcessorPipeline

use of org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorPipeline in project lucene-solr by apache.

the class TestSpanQueryParserSimpleSample method testBasicDemo.

public void testBasicDemo() throws Exception {
    SyntaxParser queryParser = new StandardSyntaxParser();
    // convert the CharSequence into a QueryNode tree
    QueryNode queryTree = queryParser.parse("body:text", null);
    // create a config handler with a attribute used in
    // UniqueFieldQueryNodeProcessor
    QueryConfigHandler spanQueryConfigHandler = new SpansQueryConfigHandler();
    spanQueryConfigHandler.set(SpansQueryConfigHandler.UNIQUE_FIELD, "index");
    // set up the processor pipeline with the ConfigHandler
    // and create the pipeline for this simple demo
    QueryNodeProcessorPipeline spanProcessorPipeline = new QueryNodeProcessorPipeline(spanQueryConfigHandler);
    // @see SpansValidatorQueryNodeProcessor
    spanProcessorPipeline.add(new SpansValidatorQueryNodeProcessor());
    // @see UniqueFieldQueryNodeProcessor
    spanProcessorPipeline.add(new UniqueFieldQueryNodeProcessor());
    // print to show out the QueryNode tree before being processed
    if (VERBOSE)
        System.out.println(queryTree);
    // Process the QueryTree using our new Processors
    queryTree = spanProcessorPipeline.process(queryTree);
    // print to show out the QueryNode tree after being processed
    if (VERBOSE)
        System.out.println(queryTree);
    // create a instance off the Builder
    SpansQueryTreeBuilder spansQueryTreeBuilder = new SpansQueryTreeBuilder();
    // convert QueryNode tree to span query Objects
    SpanQuery spanquery = spansQueryTreeBuilder.build(queryTree);
    assertTrue(spanquery instanceof SpanTermQuery);
    assertEquals(spanquery.toString(), "index:text");
}
Also used : QueryNodeProcessorPipeline(org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorPipeline) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) OrQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) QueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler) SyntaxParser(org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser) StandardSyntaxParser(org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser) StandardSyntaxParser(org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Aggregations

QueryNodeProcessorPipeline (org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessorPipeline)2 QueryConfigHandler (org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler)1 OrQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode)1 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)1 SyntaxParser (org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser)1 StandardSyntaxParser (org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser)1 WildcardQueryNodeProcessor (org.apache.lucene.queryparser.flexible.standard.processors.WildcardQueryNodeProcessor)1 SpanQuery (org.apache.lucene.search.spans.SpanQuery)1 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)1