Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class QueryParserUtil

    This class defines utility methods to (help) parse query strings into Lucene.Net.Search.Query objects.

    Inheritance
    object
    QueryParserUtil
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.QueryParsers.Flexible.Standard
    Assembly: Lucene.Net.QueryParser.dll
    Syntax
    public sealed class QueryParserUtil

    Methods

    Escape(string)

    Returns a string where those characters that TextParser expects to be escaped are escaped by a preceding </code>.

    Declaration
    public static string Escape(string s)
    Parameters
    Type Name Description
    string s
    Returns
    Type Description
    string
    Exceptions
    Type Condition
    ArgumentNullException

    s is null

    Parse(string, string[], Occur[], Analyzer)

    Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

    Usage:
    string[] fields = {"filename", "contents", "description"};
    Occur[] flags = {Occur.SHOULD,
        Occur.MUST,
        Occur.MUST_NOT};
    MultiFieldQueryParser.Parse("query", fields, flags, analyzer);

    The code above would construct a query:
    (filename:query) +(contents:query) -(description:query)
    Declaration
    public static Query Parse(string query, string[] fields, Occur[] flags, Analyzer analyzer)
    Parameters
    Type Name Description
    string query

    Query string to parse

    string[] fields

    Fields to search on

    Occur[] flags

    Flags describing the fields

    Analyzer analyzer

    Analyzer to use

    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    ArgumentException

    if the length of the fields array differs from the length of the flags array

    ArgumentNullException

    fields or flags is null

    Parse(string[], string[], Analyzer)

    Parses a query which searches on the fields specified.

    If x fields are specified, this effectively constructs:
    (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
    Declaration
    public static Query Parse(string[] queries, string[] fields, Analyzer analyzer)
    Parameters
    Type Name Description
    string[] queries

    Queries strings to parse

    string[] fields

    Fields to search on

    Analyzer analyzer

    Analyzer to use

    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    ArgumentException

    if the length of the queries array differs from the length of the fields array

    ArgumentNullException

    queries or fields is null

    Parse(string[], string[], Occur[], Analyzer)

    Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

    Usage:
    string[] query = {"query1", "query2", "query3"};
    string[] fields = {"filename", "contents", "description"};
    Occur[] flags = {Occur.SHOULD,
        Occur.MUST,
        Occur.MUST_NOT};
    MultiFieldQueryParser.Parse(query, fields, flags, analyzer);

    The code above would construct a query:
    (filename:query1) +(contents:query2) -(description:query3)
    Declaration
    public static Query Parse(string[] queries, string[] fields, Occur[] flags, Analyzer analyzer)
    Parameters
    Type Name Description
    string[] queries

    Queries string to parse

    string[] fields

    Fields to search on

    Occur[] flags

    Flags describing the fields

    Analyzer analyzer

    Analyzer to use

    Returns
    Type Description
    Query
    Exceptions
    Type Condition
    ArgumentException

    if the length of the queries, fields, and flags array differ

    ArgumentNullException

    queries, fields or flags is null

    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.