Пример #1
0
        private static IEnumerable <string> GetSearchTerms(string searchTerm)
        {
            List <string> result   = new List <string>();
            var           analyzer = new PanGuAnalyzer();
            StringReader  sr       = new StringReader(searchTerm);
            TokenStream   stream   = analyzer.TokenStream(null, sr);
            bool          hasnext  = stream.IncrementToken();

            System.DateTime start = System.DateTime.Now;
            ITermAttribute  ita;

            while (hasnext)
            {
                ita = stream.GetAttribute <ITermAttribute>();
                result.Add(ita.Term);
                hasnext = stream.IncrementToken();
            }
            stream.CloneAttributes();
            sr.Close();
            analyzer.Dispose();

            var resultString = string.Join(" ", result);

            return(resultString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                   .Concat(new[] { searchTerm })
                   .Distinct(StringComparer.OrdinalIgnoreCase)
                   .Select(Escape));
        }