org.apache.lucene.queryparser.xml

## Class CoreParser

- java.lang.Object
- - org.apache.lucene.queryparser.xml.CoreParser

- All Implemented Interfaces:
    SpanQueryBuilder, QueryBuilder
  Direct Known Subclasses:
    CorePlusQueriesParser

      public class CoreParser
      extends Object
      implements QueryBuilder, SpanQueryBuilder

  Assembles a QueryBuilder which uses only core Lucene Query objects

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Analyzer` | `analyzer`
    `protected String` | `defaultField`
    `static EntityResolver` | `DISALLOW_EXTERNAL_ENTITY_RESOLVER`
    `protected QueryParser` | `parser`
    `protected QueryBuilderFactory` | `queryFactory`
    `protected SpanQueryBuilderFactory` | `spanFactory`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `CoreParser(Analyzer analyzer, QueryParser parser)` Construct an XML parser that uses a single instance QueryParser for handling UserQuery tags - all parse operations are synchronised on this parser
    `` | `CoreParser(String defaultField, Analyzer analyzer)` Constructs an XML parser that creates a QueryParser for each UserQuery request.
    `protected` | `CoreParser(String defaultField, Analyzer analyzer, QueryParser parser)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addQueryBuilder(String nodeName, QueryBuilder builder)`
    `void` | `addSpanBuilder(String nodeName, SpanQueryBuilder builder)`
    `void` | `addSpanQueryBuilder(String nodeName, SpanQueryBuilder builder)`
    `protected EntityResolver` | `getEntityResolver()` Returns a SAX `EntityResolver` to be used by `DocumentBuilder`.
    `protected ErrorHandler` | `getErrorHandler()` Subclass and override to return a SAX `ErrorHandler` to be used by `DocumentBuilder`.
    `Query` | `getQuery(Element e)`
    `SpanQuery` | `getSpanQuery(Element e)`
    `Query` | `parse(InputStream xmlStream)` Parses the given stream as XML file and returns a `Query`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### defaultField

          protected String defaultField

    - #### analyzer

          protected Analyzer analyzer

    - #### parser

          protected QueryParser parser

    - #### queryFactory

          protected QueryBuilderFactory queryFactory

    - #### spanFactory

          protected final SpanQueryBuilderFactory spanFactory

    - #### DISALLOW_EXTERNAL_ENTITY_RESOLVER

          public static final EntityResolver DISALLOW_EXTERNAL_ENTITY_RESOLVER

  - ### Constructor Detail

    - #### CoreParser

          public CoreParser(Analyzer analyzer,
                            QueryParser parser)

      Construct an XML parser that uses a single instance QueryParser for handling UserQuery tags - all parse operations are synchronised on this parser
      Parameters:
        `parser` - A QueryParser which will be synchronized on during parse calls.

    - #### CoreParser

          public CoreParser(String defaultField,
                            Analyzer analyzer)

      Constructs an XML parser that creates a QueryParser for each UserQuery request.
      Parameters:
        `defaultField` - The default field name used by QueryParsers constructed for UserQuery tags

    - #### CoreParser

          protected CoreParser(String defaultField,
                               Analyzer analyzer,
                               QueryParser parser)

  - ### Method Detail

    - #### parse

          public Query parse(InputStream xmlStream)
                      throws ParserException

      Parses the given stream as XML file and returns a `Query`. By default this disallows external entities for security reasons.
      Throws:
        `ParserException`

    - #### addQueryBuilder

          public void addQueryBuilder(String nodeName,
                                      QueryBuilder builder)

    - #### addSpanBuilder

          public void addSpanBuilder(String nodeName,
                                     SpanQueryBuilder builder)

    - #### addSpanQueryBuilder

          public void addSpanQueryBuilder(String nodeName,
                                          SpanQueryBuilder builder)

    - #### getEntityResolver

          protected EntityResolver getEntityResolver()

      Returns a SAX `EntityResolver` to be used by `DocumentBuilder`. By default this returns `DISALLOW_EXTERNAL_ENTITY_RESOLVER`, which disallows the expansion of external entities (for security reasons). To restore legacy behavior, override this method to return `null`.

    - #### getErrorHandler

          protected ErrorHandler getErrorHandler()

      Subclass and override to return a SAX `ErrorHandler` to be used by `DocumentBuilder`. By default this returns `null` so no error handler is used. This method can be used to redirect XML parse errors/warnings to a custom logger.

    - #### getQuery

          public Query getQuery(Element e)
                         throws ParserException

      Specified by:
        `getQuery` in interface `QueryBuilder`
      Throws:
        `ParserException`

    - #### getSpanQuery

          public SpanQuery getSpanQuery(Element e)
                                 throws ParserException

      Specified by:
        `getSpanQuery` in interface `SpanQueryBuilder`
      Throws:
        `ParserException`

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.