19 using System.Collections.Generic;
22 using Term = Lucene.Net.Index.Term;
29 using Query = Lucene.Net.Search.Query;
33 using SpanQuery = Lucene.Net.Search.Spans.SpanQuery;
36 namespace Lucene.Net.Search.Payloads
69 public virtual ICollection<byte[]> GetPayloadsForQuery(
Query query)
71 ICollection<byte[]> payloads =
new List<byte[]>();
72 QueryToSpanQuery(query, payloads);
76 private void QueryToSpanQuery(
Query query, ICollection<byte[]> payloads)
82 for (
int i = 0; i < queryClauses.Length; i++)
84 if (!queryClauses[i].IsProhibited)
86 QueryToSpanQuery(queryClauses[i].
Query, payloads);
94 for (
int i = 0; i < phraseQueryTerms.Length; i++)
100 bool inorder =
false;
108 sp.Boost = query.
Boost;
109 GetPayloads(payloads, sp);
114 stq.Boost = query.
Boost;
115 GetPayloads(payloads, stq);
119 GetPayloads(payloads, (SpanQuery) query);
123 QueryToSpanQuery(((FilteredQuery) query).
Query, payloads);
128 for (IEnumerator<Query> iterator = ((DisjunctionMaxQuery)query).GetEnumerator(); iterator.MoveNext(); )
130 QueryToSpanQuery(iterator.Current, payloads);
136 System.Collections.Generic.IList<
Term[]> termArrays = mpq.GetTermArrays();
137 int[] positions = mpq.GetPositions();
138 if (positions.Length > 0)
141 int maxPosition = positions[positions.Length - 1];
142 for (
int i = 0; i < positions.Length - 1; ++i)
144 if (positions[i] > maxPosition)
146 maxPosition = positions[i];
150 IList<Query>[] disjunctLists =
new IList<Query>[maxPosition + 1];
151 int distinctPositions = 0;
153 for (
int i = 0; i < termArrays.Count; ++i)
155 Term[] termArray = termArrays[i];
156 IList<Query> disjuncts = disjunctLists[positions[i]];
157 if (disjuncts == null)
159 disjuncts = (disjunctLists[positions[i]] =
new List<Query>(termArray.Length));
162 foreach(
Term term
in termArray)
168 int positionGaps = 0;
170 SpanQuery[] clauses =
new SpanQuery[distinctPositions];
171 for (
int i = 0; i < disjunctLists.Length; ++i)
173 IList<Query> disjuncts = disjunctLists[i];
174 if (disjuncts != null)
176 clauses[position++] =
new SpanOrQuery((SpanQuery[]) (disjuncts.ToArray()));
185 bool inorder = (slop == 0);
188 sp.Boost = query.Boost;
189 GetPayloads(payloads, sp);
194 private void GetPayloads(ICollection<byte[]> payloads, SpanQuery query)
196 Spans.Spans spans = query.GetSpans(reader);
198 while (spans.Next() ==
true)
200 if (spans.IsPayloadAvailable())
202 ICollection<byte[]> payload = spans.GetPayload();
203 foreach (byte[] bytes
in payload)