public SnippetReader(TextReader line_reader, string[] query_terms, bool full_text, int context_length, int snippet_length) { this.line_reader = line_reader; this.found_snippet_length = 0; this.full_text = full_text; this.context_length = (context_length > 0 ? context_length : context_length_default); this.snippet_length = (snippet_length > 0 ? snippet_length : snippet_length_default); if (query_terms == null) { return; } this.sliding_window = new SlidingWindow(this.context_length); // remove stop words from query_terms query_terms_list = new ArrayList(query_terms.Length); foreach (string term in query_terms) { if (LuceneCommon.IsStopWord(term)) { continue; } query_terms_list.Add(term); } //Console.WriteLine ("Creating snippet reader"); }
static void AddSearchTermInfo(QueryPart part, SearchTermResponse response, StringBuilder sb) { if (part.Logic == QueryPartLogic.Prohibited) { return; } if (part is QueryPart_Or) { ICollection sub_parts; sub_parts = ((QueryPart_Or)part).SubParts; foreach (QueryPart qp in sub_parts) { AddSearchTermInfo(qp, response, sb); } return; } if (!(part is QueryPart_Text)) { return; } QueryPart_Text tp; tp = (QueryPart_Text)part; string [] split; split = tp.Text.Split(' '); // First, remove stop words for (int i = 0; i < split.Length; ++i) { if (LuceneCommon.IsStopWord(split [i])) { split [i] = null; } } // Assemble the phrase minus stop words sb.Length = 0; for (int i = 0; i < split.Length; ++i) { if (split [i] == null) { continue; } if (sb.Length > 0) { sb.Append(' '); } sb.Append(split [i]); } response.ExactText.Add(sb.ToString()); // Now assemble a stemmed version sb.Length = 0; // clear the previous value for (int i = 0; i < split.Length; ++i) { if (split [i] == null) { continue; } if (sb.Length > 0) { sb.Append(' '); } sb.Append(LuceneCommon.Stem(split [i].ToLower())); } response.StemmedText.Add(sb.ToString()); }