();
for (int i = 0; i < fields.Length; i++)
{
clauses.Add(new BooleanClause(GetRangeQuery(fields[i], part1, part2, inclusive), BooleanClause.Occur.SHOULD));
}
return GetBooleanQuery(clauses, true);
}
return base.GetRangeQuery(field, part1, part2, inclusive);
}
/// Parses a query which searches on the fields specified.
///
/// If x fields are specified, this effectively constructs:
///
///
/// <code>
/// (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
/// </code>
///
///
///
/// Queries strings to parse
///
/// Fields to search on
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the queries array differs from the length of
/// the fields array
///
/// Use {@link #Parse(Version,String[],String[],Analyzer)}
/// instead
///
[Obsolete("Use Parse(Version,String[],String[],Analyzer) instead")]
public static Query Parse(System.String[] queries, System.String[] fields, Analyzer analyzer)
{
return Parse(Version.LUCENE_24, queries, fields, analyzer);
}
/// Parses a query which searches on the fields specified.
///
/// If x fields are specified, this effectively constructs:
///
///
/// <code>
/// (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
/// </code>
///
///
///
/// Lucene version to match; this is passed through to
/// QueryParser.
///
/// Queries strings to parse
///
/// Fields to search on
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the queries array differs from the length of
/// the fields array
///
public static Query Parse(Version matchVersion, System.String[] queries, System.String[] fields, Analyzer analyzer)
{
if (queries.Length != fields.Length)
throw new System.ArgumentException("queries.length != fields.length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
Query q = qp.Parse(queries[i]);
if (q != null && (!(q is BooleanQuery) || ((BooleanQuery) q).GetClauses().Length > 0))
{
bQuery.Add(q, BooleanClause.Occur.SHOULD);
}
}
return bQuery;
}
/// 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"};
/// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
/// BooleanClause.Occur.MUST,
/// BooleanClause.Occur.MUST_NOT};
/// MultiFieldQueryParser.parse("query", fields, flags, analyzer);
///
///
///
/// The code above would construct a query:
///
///
/// (filename:query) +(contents:query) -(description:query)
///
///
///
///
/// Query string to parse
///
/// Fields to search on
///
/// Flags describing the fields
///
/// Analyzer to use
///
/// ParseException if query parsing fails
/// IllegalArgumentException if the length of the fields array differs
/// from the length of the flags array
///
/// Use
/// {@link #Parse(Version, String, String[], BooleanClause.Occur[], Analyzer)}
/// instead
///
[Obsolete("Use Parse(Version, String, String[], BooleanClause.Occur[], Analyzer) instead")]
public static Query Parse(System.String query, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
{
return Parse(Version.LUCENE_24, query, fields, flags, 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:
/// <code>
/// String[] fields = {"filename", "contents", "description"};
/// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
/// BooleanClause.Occur.MUST,
/// BooleanClause.Occur.MUST_NOT};
/// MultiFieldQueryParser.parse("query", fields, flags, analyzer);
/// </code>
///
///
/// The code above would construct a query:
///
///
/// <code>
/// (filename:query) +(contents:query) -(description:query)
/// </code>
///
///
///
/// Lucene version to match; this is passed through to
/// QueryParser.
///
/// Query string to parse
///
/// Fields to search on
///
/// Flags describing the fields
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the fields array differs from the length of
/// the flags array
///
public static Query Parse(Version matchVersion, System.String query, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
{
if (fields.Length != flags.Length)
throw new System.ArgumentException("fields.length != flags.length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
Query q = qp.Parse(query);
if (q != null && (!(q is BooleanQuery) || ((BooleanQuery) q).GetClauses().Length > 0))
{
bQuery.Add(q, flags[i]);
}
}
return bQuery;
}
/// 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"};
/// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
/// BooleanClause.Occur.MUST,
/// BooleanClause.Occur.MUST_NOT};
/// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
///
///
///
/// The code above would construct a query:
///
///
/// (filename:query1) +(contents:query2) -(description:query3)
///
///
///
///
/// Queries string to parse
///
/// Fields to search on
///
/// Flags describing the fields
///
/// Analyzer to use
///
/// ParseException if query parsing fails
/// IllegalArgumentException if the length of the queries, fields,
/// and flags array differ
///
/// Used
/// {@link #Parse(Version, String[], String[], BooleanClause.Occur[], Analyzer)}
/// instead
///
[Obsolete("Use Parse(Version, String[], String[], BooleanClause.Occur[], Analyzer) instead")]
public static Query Parse(System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
{
return Parse(Version.LUCENE_24, queries, fields, flags, 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:
/// <code>
/// String[] query = {"query1", "query2", "query3"};
/// String[] fields = {"filename", "contents", "description"};
/// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
/// BooleanClause.Occur.MUST,
/// BooleanClause.Occur.MUST_NOT};
/// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
/// </code>
///
///
/// The code above would construct a query:
///
///
/// <code>
/// (filename:query1) +(contents:query2) -(description:query3)
/// </code>
///
///
///
/// Lucene version to match; this is passed through to
/// QueryParser.
///
/// Queries string to parse
///
/// Fields to search on
///
/// Flags describing the fields
///
/// Analyzer to use
///
/// ParseException
/// if query parsing fails
///
/// IllegalArgumentException
/// if the length of the queries, fields, and flags array differ
///
public static Query Parse(Version matchVersion, System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
{
if (!(queries.Length == fields.Length && queries.Length == flags.Length))
throw new System.ArgumentException("queries, fields, and flags array have have different length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
Query q = qp.Parse(queries[i]);
if (q != null && (!(q is BooleanQuery) || ((BooleanQuery) q).GetClauses().Length > 0))
{
bQuery.Add(q, flags[i]);
}
}
return bQuery;
}
}
}