lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Кузнецов Владимир Николаевич <kuznet...@skbkontur.ru>
Subject [Lucene.Net] How to do that the results are displayed in the first original tokens and them with synonyms?
Date Thu, 30 Jun 2011 10:59:15 GMT
How to do that the results are displayed in the first original tokens and them with synonyms?

 My Analyzer(part) :

public override TokenStream TokenStream(string fieldName, TextReader reader)
 { TokenStream result = new StandardTokenizer(reader); result = new LowerCaseFilter(result);
result = new StopFilter(result, stoptable); result = new SynonymFilter(result, synonymEngine);
result = new ExtendedRussianStemFilter(result, charset); return result; }
 My SynonymFilter :

internal class SynonymFilter : TokenFilter
 {
 private readonly ISynonymEngine engine;

 private readonly Queue<Token> synonymTokenQueue
 = new Queue<Token>();

 public SynonymFilter(TokenStream tokenStream, ISynonymEngine engine) : base(tokenStream)
 { this.engine = engine; } 
public override Token Next()
 {
 if (synonymTokenQueue.Count > 0)
 { return synonymTokenQueue.Dequeue(); } 
Token t = input.Next();

 if (t == null)
 return null;

 if (t.Type() == "<SYNONYM>")
 return t;

 IEnumerable<string> synonyms = engine.GetSynonyms(t.TermText());

 if (synonyms == null)
 { return t; } 
foreach (string syn in synonyms)
 {
 if (!t.TermText().Equals(syn))
 { var synToken = new Token(syn, t.StartOffset(), t.EndOffset(), "<SYNONYM>"); synToken.SetPositionIncrement(0);
synonymTokenQueue.Enqueue(synToken); }
 }

 return t;
 }
 }

Thanks!

Mime
View raw message