public static void Output(QueryResult result) { if (result.docs.Count > 0) { foreach (QueryResult.SearchInfo info in result.docs.Keys) { Console.WriteLine("index :" + info.IndexName); foreach (QueryResult.ExDocument ed in result.docs[info]) { Console.Write("Score=" + ed.score.ToString()); foreach (string s in info.Fields) { Console.Write("\t" + ed.doc.Get(s)); } Console.WriteLine(); //Response.Write(ISUtils.SupportClass.Document.ToString(ed.doc)+ "<br>"); //Console.WriteLine(string.Format("title:{0} \nhistoryName:{1}", doc.Get("id"), doc.Get("historyName"))); } } } }
private static Query GetFuzzyQuery(IndexSet indexSet, out QueryResult.SearchInfo info) { string[] fields; info = new QueryResult.SearchInfo(); info.IndexName = indexSet.IndexName; if (indexFieldsDict.Count > 0 && indexFieldsDict.ContainsKey(indexSet)) fields = indexFieldsDict[indexSet].ToArray(); else fields = indexDict[indexSet].StringFields.ToArray(); info.Fields.AddRange(fields); string[] wordAllContainArray = SupportClass.String.Split(wordsAllContains); string[] exactPhraseArray = SupportClass.String.Split(exactPhraseContain); string[] oneWordContainArray = SupportClass.String.Split(oneOfWordsAtLeastContain); string[] wordNoIncludeArray = SupportClass.String.Split(wordNotInclude); MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer); BooleanQuery queryRet = new BooleanQuery(); foreach (string words in wordAllContainArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach(string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.MUST); } } foreach (string words in exactPhraseArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach (string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.MUST); } } foreach (string words in oneWordContainArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach(string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.SHOULD); } } foreach (string words in wordNoIncludeArray) { List<string> wordList = ISUtils.CSegment.Segment.SegmentStringEx(words); foreach(string word in wordList) { Query query = parser.Parse(word); queryRet.Add(query, BooleanClause.Occur.MUST_NOT); } } return queryRet; }