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();
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        private void SetAspectGet(ICoreChildProvider childProvider)
        {
            AspectGetter = (o) =>
            {
                if (o == null)
                {
                    return("Null");
                }

                var parent = childProvider.GetDescendancyListIfAnyFor(o)?.GetMostDescriptiveParent();

                return(parent != null ? $"{o.ID} {o.GetType().Name} {o} ({parent})" : $"{o.ID} {o.GetType().Name} {o}");
            };

            _scorer           = new SearchablesMatchScorer();
            _scorer.TypeNames = new HashSet <string>(_masterCollection.Select(m => m.Key.GetType().Name).Distinct(), StringComparer.CurrentCultureIgnoreCase);
        }
예제 #5
0
        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);
        }
예제 #8
0
        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();
            }
        }