Esempio n. 1
0
        public void GIVEN_QueryParser_WHEN_ParseIsCalled_AND_QueryIsNullOrEmptyStringOrContainsWhiteSpaceOnly_THAN_ValidQueryDescriptionIsReturned(string query)
        {
            var sandoQueryParser      = new SandoQueryParser();
            var sandoQueryDescription = sandoQueryParser.Parse(null);

            Assert.IsFalse(sandoQueryDescription.IsValid);
        }
        public void TestIfQueryParsesToEmptySearchTerm()
        {
            var description = new SandoQueryParser().Parse("g_u16ActiveFault");
            var builder     = CriteriaBuilder.GetBuilder().AddFromDescription(description);
            var simple      = builder.GetCriteria() as SimpleSearchCriteria;

            Assert.IsFalse(simple.SearchTerms.Where(x => String.IsNullOrWhiteSpace(x)).ToList().Count >= 1);
        }
Esempio n. 3
0
        public void GIVEN_QueryParser_WHEN_ParseIsCalled_AND_QueryIsNormalString_THAN_ValidQueryDescriptionIsReturned(string query, string expectedQueryDescription)
        {
            var sandoQueryParser      = new SandoQueryParser();
            var sandoQueryDescription = sandoQueryParser.Parse(query);

            Assert.IsTrue(sandoQueryDescription.IsValid);
            Assert.AreEqual(expectedQueryDescription, sandoQueryDescription.ToString());
        }
Esempio n. 4
0
        public void ParseWithNegation()
        {
            var sandoQueryParser      = new SandoQueryParser();
            var sandoQueryDescription = sandoQueryParser.Parse("reorder search results -test");

            Assert.IsTrue(sandoQueryDescription.IsValid);
            Assert.IsTrue(sandoQueryDescription.SearchTerms.Count == 4);
        }
Esempio n. 5
0
        public void ParseFileH()
        {
            var sandoQueryParser      = new SandoQueryParser();
            var sandoQueryDescription = sandoQueryParser.Parse("open file:h");

            Assert.IsTrue(sandoQueryDescription.IsValid);
            Assert.IsTrue(sandoQueryDescription.SearchTerms.Count == 1);
        }
Esempio n. 6
0
        private SearchCriteria GetCriteria(string searchString, SimpleSearchCriteria searchCriteria = null)
        {
            var sandoOptions = ServiceLocator.Resolve <ISandoOptionsProvider>().GetSandoOptions();
            var description  = new SandoQueryParser().Parse(searchString);
            var builder      = CriteriaBuilder.GetBuilder().
                               AddCriteria(searchCriteria).
                               NumResults(sandoOptions.NumberOfSearchResultsReturned).AddFromDescription(description);
            var simple = builder.GetCriteria() as SimpleSearchCriteria;

            SearchCriteriaReformer.ReformSearchCriteria(simple);
            return(simple);
        }
Esempio n. 7
0
        public static string[] GetKeys(string searchKey)
        {
            SandoQueryParser parser = new SandoQueryParser();
            var description         = parser.Parse(searchKey);
            var terms             = description.SearchTerms;
            HashSet <string> keys = new HashSet <string>();

            foreach (var term in terms)
            {
                keys.Add(DictionaryHelper.GetStemmedQuery(term));
                keys.Add(term);
            }
            foreach (var quote in description.LiteralSearchTerms)
            {
                var toAdd = quote.Substring(1);
                toAdd = toAdd.Substring(0, toAdd.Length - 1);
                //unescape '\' and '"'s
                toAdd = toAdd.Replace("\\\"", "\"");
                toAdd = toAdd.Replace("\\\\", "\\");
                keys.Add(toAdd);
            }
            return(keys.ToArray());
        }