public SearchResult( IVsSearchProvider searchProvider, IExtensionDataItemView item) { // If either of these are null, we end up with very hard to trace exceptions that // in Visual Studio that don't really describe the issue. To save us future headaches.. Debug.Assert(searchProvider != null); Debug.Assert(item != null); this.SearchProvider = searchProvider; this.item = item; }
private void ScoreItem( IList <Tuple <int, IExtensionDataItemView> > searchResults, IExtensionDataItemView item, IEnumerable <string> loweredTokens) { int score = 0; int tokensMatched = 0; var loweredTitle = item.Title.ToLowerInvariant(); var loweredDescription = item.Description.ToLowerInvariant(); foreach (var token in loweredTokens) { var titleContainsToken = loweredTitle.Contains(token); var descriptionContainsToken = loweredDescription.Contains(token); // TODO: less naive. if (titleContainsToken || descriptionContainsToken) { ++tokensMatched; // Title matches are worth twice as much. if (titleContainsToken) { score += 2; } if (descriptionContainsToken) { score += 1; } } } // Only return items that matched all of the tokens. if (tokensMatched == loweredTokens.Count()) { searchResults.Add(Tuple.Create(score, item)); } }