void AddToResult(SearchResult result, Postings found) { foreach (Posting posting in found) { result.Add(new SearchHit(posting.Record)); } }
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; }
void SearchToken(SearchResult result, Token token) { Postings postings = (Postings)_postings[token.Value]; if (null != postings) { AddToResult(result, postings); } }
void AssertSearchContains(SearchResult result, params IRecord[] expected) { foreach (IRecord record in expected) { if (!result.Contains(record)) { Fail(string.Format("Expected record \"{0}\"!", record["Title"])); } } AssertEquals("result.Count", expected.Length, result.Count); }
SearchResult IncludeAny(ITokenizer tokenizer, Token token) { SearchResult result = new SearchResult(); while (null != token) { SearchToken(result, token); token = tokenizer.NextToken(); } return result; }
public void SetUp() { _record1 = CreateRecord("Teresa", 43); _record2 = CreateRecord("M�rcia", 26); _record3 = CreateRecord("Bamboo", 27); _result = new SearchResult(); _result.Add(new SearchHit(_record1)); _result.Add(new SearchHit(_record2)); _result.Add(new SearchHit(_record3)); }
void AssertSearchHits(SearchResult result, params IRecord[] expectedRecords) { AssertEquals(expectedRecords.Length, result.Count); for (int i=0; i<expectedRecords.Length; ++i) { IRecord expected = expectedRecords[i]; IRecord actual = result[i].Record; AssertEquals(string.Format("{0} != {1}", expected["Name"], actual["Name"]), expected, actual); } }
public void TestIntersect() { SearchResult other = new SearchResult(); other.Add(new SearchHit(_record3)); other.Add(new SearchHit(_record1)); AssertSearchHits(_result.Intersect(other), _record1, _record3); other = new SearchResult(); other.Add(new SearchHit(_record2)); AssertSearchHits(_result.Intersect(other), _record2); AssertEquals(0, _result.Intersect(new SearchResult()).Count); AssertSearchHits(_result.Intersect(_result), _record1, _record2, _record3); }
/// <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; }