protected override IList <IMapsDirectlyToDatabaseTable> GetListAfterSearch(string searchText, CancellationToken token) { if (token.IsCancellationRequested) { return(new List <IMapsDirectlyToDatabaseTable>()); } if (int.TryParse(txtId.Text.ToString(), out int searchForID)) { _scorer.ID = searchForID; } else { _scorer.ID = null; } var dict = _scorer.ScoreMatches(_masterCollection, searchText, token, null); //can occur if user punches many keys at once if (dict == null) { return(new List <IMapsDirectlyToDatabaseTable>()); } return(_scorer.ShortList(dict, MaxMatches, _activator)); }
public void Find_CohortAggregateContainer_ByFreeText(bool userSetting) { var container = WhenIHaveA <CohortAggregateContainer>(); container.Name = "All the trolls in the troll kingdom"; UserSettings.ScoreZeroForCohortAggregateContainers = userSetting; var scorer = new SearchablesMatchScorer(); scorer.TypeNames.Add("CohortAggregateContainer"); var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null); // user is searching for the text 'troll' var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "troll", CancellationToken.None, new List <Type>()); var score = scores.Single(d => Equals(d.Key.Key, container)); if (userSetting) { // although the text appears in the search they are not doing it by exact type name and their settings // mean they don't want to see these objects by default. Assert.AreEqual(0, score.Value); } else { Assert.Greater(score.Value, 0); } }
private void TestScoringFlag(Action <Catalogue, ExtractableDataSet> setter, bool expectedResult) { // Filter is hungry and eager to please. If you want to see ProjectSpecific Catalogues then // that it will show you them regardless of other settings. Likewise clicking Deprecated shows // all deprecated catalogues regardless of other settings. // // So set all to false to except the condition we are testing UserSettings.ShowDeprecatedCatalogues = false; UserSettings.ShowNonExtractableCatalogues = false; UserSettings.ShowProjectSpecificCatalogues = false; UserSettings.ShowInternalCatalogues = false; UserSettings.ShowColdStorageCatalogues = false; var c = WhenIHaveA <Catalogue>(); c.Name = "Bunny"; c.SaveToDatabase(); // this makes c extractable (the usual case for Catalogues) var eds = new ExtractableDataSet(Repository, c); eds.SaveToDatabase(); setter(c, eds); c.SaveToDatabase(); var scorer = new SearchablesMatchScorer() { RespectUserSettings = true }; var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null); // user is searching for the text 'troll' var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "Bunny", CancellationToken.None, new List <Type>()); var score = scores.Single(d => Equals(d.Key.Key, c)); if (expectedResult) { Assert.Greater(score.Value, 0); } else { // score 0 and don't be included in results Assert.AreEqual(0, score.Value); } // Cleanup test foreach (var d in Repository.GetAllObjects <ExtractableDataSet>()) { d.DeleteInDatabase(); } foreach (var cat in Repository.GetAllObjects <Catalogue>()) { cat.DeleteInDatabase(); } }
private void FetchMatches(string text, CancellationToken cancellationToken) { var scorer = new SearchablesMatchScorer(); scorer.TypeNames = _typeNames; //do short code substitutions e.g. ti for TableInfo if (!string.IsNullOrWhiteSpace(text)) { foreach (var kvp in ShortCodes) { text = Regex.Replace(text, $@"\b{kvp.Key}\b", kvp.Value.Name); } } //if user hasn't typed any explicit Type filters if (string.IsNullOrWhiteSpace(text) || !_typeNames.Intersect(text.Split(' '), StringComparer.CurrentCultureIgnoreCase).Any()) { //add the buttons pressed foreach (var showOnlyType in showOnlyTypes) { text = text + " " + showOnlyType.Name; } } //Search the tokens for also inclusions e.g. "Pipeline" becomes "Pipeline PipelineCompatibleWithUseCaseNode" if (!string.IsNullOrWhiteSpace(text)) { foreach (var s in text.Split(' ').ToArray()) { if (AlsoIncludes.ContainsKey(s)) { foreach (var v in AlsoIncludes[s]) { text += " " + v.Name; } } } } var scores = scorer.ScoreMatches(_searchables, text, cancellationToken); if (scores == null) { return; } lock (oMatches) { _matches = scores .Where(score => score.Value > 0) .OrderByDescending(score => score.Value) .ThenByDescending(id => id.Key.Key.ID) //favour newer objects over ties .Take(MaxMatches) .Select(score => score.Key.Key) .ToList(); } }
protected override IList <IMapsDirectlyToDatabaseTable> GetListAfterSearch(string searchText) { return(_scorer .ScoreMatches(_masterCollection, searchText, new CancellationToken(), null) .Where(score => score.Value > 0) .OrderByDescending(score => score.Value) .ThenByDescending(id => id.Key.Key.ID) //favour newer objects over ties .Take(MaxMatches) .Select(score => score.Key.Key) .ToList()); }
private void FetchMatches(string text, CancellationToken cancellationToken) { var scorer = new SearchablesMatchScorer(); scorer.TypeNames = _typeNames; if (!string.IsNullOrWhiteSpace(text)) { foreach (var kvp in ShortCodes) { text = Regex.Replace(text, $@"\b{kvp.Key}\b", kvp.Value.Name); } } //if user hasn't typed any explicit Type filters if (string.IsNullOrWhiteSpace(text) || !_typeNames.Intersect(text.Split(' '), StringComparer.CurrentCultureIgnoreCase).Any()) { //add the buttons pressed foreach (var showOnlyType in showOnlyTypes) { text = text + " " + showOnlyType.Name; } } var scores = scorer.ScoreMatches(_searchables, text, cancellationToken); if (scores == null) { return; } lock (oMatches) { _matches = scores .Where(score => score.Value > 0) .OrderByDescending(score => score.Value) .ThenByDescending(id => id.Key.Key.ID) //favour newer objects over ties .Take(MaxMatches) .Select(score => score.Key.Key) .ToList(); } }
public void Find_CohortAggregateContainer_ByTypeName(bool userSetting) { var container = WhenIHaveA <CohortAggregateContainer>(); UserSettings.ScoreZeroForCohortAggregateContainers = userSetting; var scorer = new SearchablesMatchScorer(); scorer.TypeNames.Add("CohortAggregateContainer"); var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null); var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "", CancellationToken.None, new List <Type>() { typeof(CohortAggregateContainer) }); var score = scores.Single(d => Equals(d.Key.Key, container)); Assert.Greater(score.Value, 0); }
public void Find_ExactMatch_ScoresHigher() { var cata = WhenIHaveA <Catalogue>(); cata.Name = "FF"; var proj = WhenIHaveA <Project>(); proj.Name = "FFFF"; var scorer = new SearchablesMatchScorer(); var childProvider = new DataExportChildProvider(RepositoryLocator, null, new ThrowImmediatelyCheckNotifier(), null); var scores = scorer.ScoreMatches(childProvider.GetAllSearchables(), "FF", CancellationToken.None, new List <Type>()); var cataScore = scores.Single(d => Equals(d.Key.Key, cata)); var projScore = scores.Single(d => Equals(d.Key.Key, proj)); // Both score because they have the text FF Assert.Greater(cataScore.Value, 0); Assert.Greater(projScore.Value, 0); // Catalogue scores higher because it is an exact match to the name Assert.Greater(cataScore.Value, projScore.Value); }
private void FetchMatches(string text, CancellationToken cancellationToken) { var scorer = new SearchablesMatchScorer(); scorer.TypeNames = _typeNames; var scores = scorer.ScoreMatches(_searchables, text, cancellationToken, showOnlyTypes); if (scores == null) { return; } lock (oMatches) { _matches = scores .Where(score => score.Value > 0) .OrderByDescending(score => score.Value) .ThenByDescending(id => id.Key.Key.ID) //favour newer objects over ties .Take(MaxMatches) .Select(score => score.Key.Key) .ToList(); } }