void AddToResult(SearchResult result, Postings found) { foreach (Posting posting in found) { result.Add(new SearchHit(posting.Record)); } }
void SearchToken(SearchResult result, Token token) { Postings postings = (Postings)_postings[token.Value]; if (null != postings) { AddToResult(result, postings); } }
SearchResult IncludeAll(ITokenizer tokenizer, Token token) { ArrayList results = new ArrayList(); while (null != token) { SearchResult tokenResult = new SearchResult(); SearchToken(tokenResult, token); results.Add(tokenResult); token = tokenizer.NextToken(); } SearchResult result = (SearchResult)results[0]; for (int i=1; i<results.Count && result.Count > 0; ++i) { result = result.Intersect((SearchResult)results[i]); } return result; }
SearchResult IncludeAny(ITokenizer tokenizer, Token token) { SearchResult result = new SearchResult(); while (null != token) { SearchToken(result, token); token = tokenizer.NextToken(); } return result; }
/// <summary> /// Build a new SearchResult object including /// only those elements for which the /// filter returns true. /// </summary> /// <param name="filter">filter</param> /// <returns>a new SearchResult containing all the elements for which /// <see cref="ISearchHitFilter.Test"/> returned true</returns> public SearchResult Filter(ISearchHitFilter filter) { SearchResult result = new SearchResult(); foreach (SearchHit hit in _hits) { if (filter.Test(hit)) { result.Add(hit); } } return result; }
/// <summary> /// Set intersection operation. Creates /// a new SearchResult with all the records /// that exist in both SearchResult objects. /// </summary> /// <param name="other"></param> /// <returns>a SearchResult representing the /// intersection between the this and other objects /// </returns> /// <remarks>all the SearchHit objects in /// the resulting SearchResult are clones from /// the original ones combined to the ones in /// other</remarks> public SearchResult Intersect(SearchResult other) { SearchResult result = new SearchResult(); foreach (SearchHit hit in _hits) { SearchHit otherHit = other.FindSearchHit(hit.Record); if (null != otherHit) { SearchHit resultingHit = hit.Clone(); resultingHit.Combine(otherHit); result.Add(resultingHit); } } return result; }