19 using System.Collections.Generic;
20 using Lucene.Net.Search;
26 using Query = Lucene.Net.Search.Query;
29 namespace Lucene.Net.QueryParsers
39 protected internal string[] fields;
40 protected internal IDictionary<string, float> boosts;
77 : this(matchVersion, fields, analyzer)
108 : base(matchVersion, null, analyzer)
110 this.fields = fields;
113 protected internal override Query GetFieldQuery(
string field,
string queryText,
int slop)
117 IList<BooleanClause> clauses =
new List<BooleanClause>();
118 for (
int i = 0; i < fields.Length; i++)
120 Query q = base.GetFieldQuery(fields[i], queryText);
127 Single boost = boosts[fields[i]];
134 if (clauses.Count == 0)
137 return GetBooleanQuery(clauses,
true);
139 Query q2 = base.GetFieldQuery(field, queryText);
144 private void ApplySlop(
Query q,
int slop)
157 protected internal override Query GetFieldQuery(System.String field, System.String queryText)
159 return GetFieldQuery(field, queryText, 0);
163 protected internal override Query GetFuzzyQuery(System.String field, System.String termStr,
float minSimilarity)
167 IList<BooleanClause> clauses =
new List<BooleanClause>();
168 for (
int i = 0; i < fields.Length; i++)
170 clauses.Add(
new BooleanClause(GetFuzzyQuery(fields[i], termStr, minSimilarity),
Occur.SHOULD));
172 return GetBooleanQuery(clauses,
true);
174 return base.GetFuzzyQuery(field, termStr, minSimilarity);
177 protected internal override Query GetPrefixQuery(System.String field, System.String termStr)
181 IList<BooleanClause> clauses =
new List<BooleanClause>();
182 for (
int i = 0; i < fields.Length; i++)
186 return GetBooleanQuery(clauses,
true);
188 return base.GetPrefixQuery(field, termStr);
191 protected internal override Query GetWildcardQuery(System.String field, System.String termStr)
195 IList<BooleanClause> clauses =
new List<BooleanClause>();
196 for (
int i = 0; i < fields.Length; i++)
200 return GetBooleanQuery(clauses,
true);
202 return base.GetWildcardQuery(field, termStr);
206 protected internal override Query GetRangeQuery(System.String field, System.String part1, System.String part2,
bool inclusive)
210 IList<BooleanClause> clauses =
new List<BooleanClause>();
211 for (
int i = 0; i < fields.Length; i++)
213 clauses.Add(
new BooleanClause(GetRangeQuery(fields[i], part1, part2, inclusive),
Occur.SHOULD));
215 return GetBooleanQuery(clauses,
true);
217 return base.GetRangeQuery(field, part1, part2, inclusive);
245 public static Query Parse(
Version matchVersion, System.String[] queries, System.String[] fields,
Analyzer analyzer)
247 if (queries.Length != fields.Length)
248 throw new System.ArgumentException(
"queries.length != fields.length");
250 for (
int i = 0; i < fields.Length; i++)
254 if (q != null && (!(q is
BooleanQuery) || ((BooleanQuery)q).GetClauses().Length > 0))
301 if (fields.Length != flags.Length)
302 throw new System.ArgumentException(
"fields.length != flags.length");
304 for (
int i = 0; i < fields.Length; i++)
308 if (q != null && (!(q is
BooleanQuery) || ((BooleanQuery)q).GetClauses().Length > 0))
310 bQuery.
Add(q, flags[i]);
355 if (!(queries.Length == fields.Length && queries.Length == flags.Length))
356 throw new System.ArgumentException(
"queries, fields, and flags array have have different length");
358 for (
int i = 0; i < fields.Length; i++)
362 if (q != null && (!(q is
BooleanQuery) || ((BooleanQuery)q).GetClauses().Length > 0))
364 bQuery.
Add(q, flags[i]);