19 using System.Collections.Generic;
23 using Lucene.Net.Index;
24 using Lucene.Net.Support;
25 using Lucene.Net.Util;
27 namespace Lucene.Net.Search
34 private List<Filter> shouldFilters = null;
39 private List<Filter> notFilters = null;
44 private List<Filter> mustFilters = null;
55 return filters[index].GetDocIdSet(reader).Iterator();
67 if (shouldFilters != null)
69 for (
int i = 0; i < shouldFilters.Count; i++)
77 DocIdSet dis = shouldFilters[i].GetDocIdSet(reader);
81 res.
Or((OpenBitSet)dis);
85 res.
InPlaceOr(GetDISI(shouldFilters, i, reader));
91 if (notFilters != null)
93 for (
int i = 0; i < notFilters.Count; i++)
102 DocIdSet dis = notFilters[i].GetDocIdSet(reader);
106 res.
AndNot((OpenBitSet)dis);
110 res.
InPlaceNot(GetDISI(notFilters, i, reader));
116 if (mustFilters != null)
118 for (
int i = 0; i < mustFilters.Count; i++)
126 DocIdSet dis = mustFilters[i].GetDocIdSet(reader);
130 res.
And((OpenBitSet)dis);
134 res.
InPlaceAnd(GetDISI(mustFilters, i, reader));
141 return FinalResult(res, reader.
MaxDoc);
165 if (mustFilters == null)
167 mustFilters =
new EquatableList<Filter>();
169 mustFilters.Add(filterClause.
Filter);
173 if (shouldFilters == null)
175 shouldFilters =
new EquatableList<Filter>();
177 shouldFilters.Add(filterClause.
Filter);
181 if (notFilters == null)
183 notFilters =
new EquatableList<Filter>();
185 notFilters.Add(filterClause.
Filter);
195 private bool EqualFilters(List<Filter> filters1, List<Filter> filters2)
197 return (filters1 == filters2) ||
198 ((filters1 != null) && filters1.Equals(filters2));
206 public override bool Equals(Object obj)
214 BooleanFilter other = (BooleanFilter)obj;
215 return EqualFilters(notFilters, other.notFilters)
216 && EqualFilters(mustFilters, other.mustFilters)
217 && EqualFilters(shouldFilters, other.shouldFilters);
224 public override int GetHashCode()
227 hash = 31 * (hash + this.ListHash(this.mustFilters));
228 hash = 31 * (hash + this.ListHash(this.notFilters));
229 hash = 31 * (hash + this.ListHash(this.shouldFilters));
234 private int ListHash(List<Filter> filters)
237 if (filters != null && filters.Count > 0)
239 for (
int i = 0; i < filters.Count; i++)
241 sum += filters[i].GetHashCode();
251 public override String ToString()
253 StringBuilder buffer =
new StringBuilder();
254 buffer.Append(
"BooleanFilter(");
255 AppendFilters(shouldFilters,
"", buffer);
256 AppendFilters(mustFilters,
"+", buffer);
257 AppendFilters(notFilters,
"-", buffer);
259 return buffer.ToString();
268 private void AppendFilters(List<Filter> filters, String occurString, StringBuilder buffer)
272 for (
int i = 0; i < filters.Count(); i++)
275 buffer.Append(occurString);
276 buffer.Append(filters[i].ToString());