private IEnumerable <SearchEngineResult> PerformQuery(ICollection <SearchEngineResult> list, Query queryOrig, int max, int blogId, int idToFilter) { Query isPublishedQuery = new TermQuery(new Term(Published, true.ToString())); Query isBlogQuery = GetBlogIdSearchQuery(blogId); var query = new BooleanQuery(); query.Add(isPublishedQuery, BooleanClause.Occur.MUST); query.Add(queryOrig, BooleanClause.Occur.MUST); query.Add(isBlogQuery, BooleanClause.Occur.MUST); IndexSearcher searcher = Searcher; TopDocs hits = searcher.Search(query, max); int length = hits.scoreDocs.Length; int resultsAdded = 0; float minScore = _settings.MinimumScore; float scoreNorm = 1.0f / hits.GetMaxScore(); for (int i = 0; i < length && resultsAdded < max; i++) { float score = hits.scoreDocs[i].score * scoreNorm; SearchEngineResult result = CreateSearchResult(searcher.Doc(hits.scoreDocs[i].doc), score); if (idToFilter != result.EntryId && result.Score > minScore && result.PublishDate < DateTime.Now) { list.Add(result); resultsAdded++; } } return(list); }
private void BindLink(RepeaterItemEventArgs e, SearchEngineResult searchResult) { var relatedLink = (HyperLink)e.Item.FindControl("Link"); var datePublished = (Literal)e.Item.FindControl("DatePublished"); var score = (Literal)e.Item.FindControl("Score"); if(relatedLink != null) { relatedLink.Text = searchResult.Title; relatedLink.NavigateUrl = Url.EntryUrl(searchResult); if (datePublished!=null) datePublished.Text = searchResult.DateSyndicated.ToShortDateString(); if (score!=null) score.Text = searchResult.Score.ToString(); } }
protected virtual SearchEngineResult CreateSearchResult(Document doc, float score) { var result = new SearchEngineResult { BlogName = doc.Get(BlogName), EntryId = NumericUtils.PrefixCodedToInt(doc.Get(Entryid)), PublishDate = DateTools.StringToDate(doc.Get(Pubdate)), Title = doc.Get(Title), Score = score }; string entryName = doc.Get(EntryName); result.EntryName = !String.IsNullOrEmpty(entryName) ? entryName : null; return(result); }
protected virtual void SearchResultsCreated(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { SearchResult = (SearchEngineResult)e.Item.DataItem; BindLink(e, SearchResult); } }