19 using System.Collections.Generic;
21 using Lucene.Net.Analysis.Tokenattributes;
22 using Lucene.Net.Index;
23 using Lucene.Net.Support;
27 namespace Lucene.Net.Search
36 private System.String[] terms =
new System.String[0];
37 private int[] termFreqs =
new int[0];
39 public virtual string Field
50 ProcessTerms(queryTerms);
57 TokenStream stream = analyzer.TokenStream(
"",
new System.IO.StringReader(queryString));
60 IList<string> terms =
new List<string>();
63 bool hasMoreTokens =
false;
68 hasMoreTokens = stream.IncrementToken();
71 terms.Add(termAtt.
Term);
72 hasMoreTokens = stream.IncrementToken();
74 ProcessTerms(terms.ToArray());
76 catch (System.IO.IOException)
83 private void ProcessTerms(System.String[] queryTerms)
85 if (queryTerms != null)
87 System.Array.Sort(queryTerms);
88 IDictionary<string, int> tmpSet =
new HashMap<string, int>(queryTerms.Length);
90 IList<string> tmpList =
new List<string>(queryTerms.Length);
91 IList<int> tmpFreqs =
new List<int>(queryTerms.Length);
93 for (
int i = 0; i < queryTerms.Length; i++)
95 var term = queryTerms[i];
96 var position = tmpSet[term];
97 if (!tmpSet.ContainsKey(term))
105 int integer = tmpFreqs[position];
106 tmpFreqs[position] = (integer + 1);
109 terms = tmpList.ToArray();
111 termFreqs =
new int[tmpFreqs.Count];
113 foreach (
int integer
in tmpFreqs)
115 termFreqs[i2++] = integer;
120 public override System.String ToString()
122 System.Text.StringBuilder sb =
new System.Text.StringBuilder();
124 for (
int i = 0; i < terms.Length; i++)
128 sb.Append(terms[i]).Append(
'/').Append(termFreqs[i]);
131 return sb.ToString();
135 public virtual int Size
137 get {
return terms.Length; }
140 public virtual System.String[] GetTerms()
145 public virtual int[] GetTermFrequencies()
150 public virtual int IndexOf(System.String term)
152 int res = System.Array.BinarySearch(terms, term);
153 return res >= 0?res:- 1;
156 public virtual int[] IndexesOf(System.String[] terms,
int start,
int len)
158 int[] res =
new int[len];
160 for (
int i = 0; i < len; i++)
162 res[i] = IndexOf(terms[i]);