private List <SueetieSearchResult> PerformQuery(List <SueetieSearchResult> list, Query queryBody, int max, bool isRestricted) { Query isRestrictedQuery = new TermQuery(new Term(IsRestricted, isRestricted.ToString())); var query = new BooleanQuery(); query.Add(queryBody, BooleanClause.Occur.MUST); if (isRestricted) { query.Add(isRestrictedQuery, BooleanClause.Occur.MUST_NOT); } IndexSearcher searcher = Searcher; TopDocs hits = searcher.Search(query, max); int length = hits.scoreDocs.Length; int resultsAdded = 0; float minScore = _config.SearchSettings.MinimumScore; float scoreNorm = 100.0f / hits.GetMaxScore(); for (int i = 0; i < length && resultsAdded < max; i++) { float score = hits.scoreDocs[i].score * scoreNorm; SueetieSearchResult result = CreateSearchResult(searcher.Doc(hits.scoreDocs[i].doc), score); if (result.Score > minScore) { string _content = HighlightContents(query, searcher.Doc(hits.scoreDocs[i].doc).GetField(Body).StringValue()); if (!string.IsNullOrEmpty(_content)) { if (string.IsNullOrEmpty(_content) || _content.Contains("»")) { _content = DataHelper.TruncateText(searcher.Doc(hits.scoreDocs[i].doc).GetField(Body).StringValue(), _bodyDisplayLength); } } else { _content = DataHelper.TruncateText(searcher.Doc(hits.scoreDocs[i].doc).GetField(Body).StringValue(), _bodyDisplayLength); } if (_content.Contains("»")) { _content = DataHelper.TruncateTextNoElipse(_content.Replace("...", string.Empty), _content.IndexOf("»") + 2); } result.HighlightedContent = _content; list.Add(result); resultsAdded++; } } return(list); }
protected virtual SueetieSearchResult CreateSearchResult(Document doc, float score) { SueetieSearchResult result = new SueetieSearchResult { ContainerName = doc.Get(ContainerName), ContentID = NumericUtils.PrefixCodedToInt(doc.Get(ContentID)), PublishDate = DateTools.StringToDate(doc.Get(Pubdate)), Title = doc.Get(Title), Score = score, ContentTypeID = NumericUtils.PrefixCodedToInt(doc.Get(ContentTypeID)), ApplicationTypeID = NumericUtils.PrefixCodedToInt(doc.Get(ApplicationTypeID)), PermaLink = doc.Get(PermaLink), Author = doc.Get(Author), ApplicationKey = doc.Get(ApplicationKey), DisplayTags = doc.Get(DisplayTags) }; return(result); }