19 using System.Collections.Generic;
22 using Lucene.Net.Analysis;
23 using Lucene.Net.Analysis.Standard;
24 using Lucene.Net.Analysis.Tokenattributes;
25 using Lucene.Net.Index;
26 using Lucene.Net.Search;
27 using Lucene.Net.Store;
29 namespace WorldNet.Net
40 static List<String> already;
54 public static void Main(String[] args)
58 Console.Out.WriteLine(typeof(
SynExpand) +
" <index path> <query>");
65 String query = args[1];
66 const string field =
"contents";
68 Query q = Expand(query, searcher,
new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), field, 0.9f);
69 System.Console.Out.WriteLine(
"Query: " + q.
ToString(field));
85 public static Query Expand(String query,
91 already =
new List<String>();
92 var top =
new List<String>();
100 var ts = a.
TokenStream(field,
new StringReader(query));
103 while (ts.IncrementToken())
105 var word = termAtt.
Term;
107 if (!already.Contains(word))
117 System.Collections.IEnumerator it = top.GetEnumerator();
118 while (it.MoveNext())
121 var word = (String) it.Current;
123 tmp.Add(tq,
Occur.SHOULD);
125 var c =
new CollectorImpl(field, boost);
139 public const String F_SYN =
"syn";
142 public const String F_WORD =
"word";
148 internal sealed
class CollectorImpl :
Collector
151 private readonly
string field;
152 private readonly
float boost;
154 public CollectorImpl(
string field,
float boost)
160 public override void SetScorer(
Scorer scorer)
165 public override void Collect(
int doc)
168 var values = d.GetValues(Syns2Index.F_SYN);
169 foreach (var syn
in values.Where(syn => !already.Contains(syn)))
177 tmp.Add(tq,
Occur.SHOULD);
181 public override void SetNextReader(
IndexReader reader,
int docBase)
183 this.reader = reader;
186 public override bool AcceptsDocsOutOfOrder