Пример #1
0
        public void GIVEN_QueryParser_WHEN_ParseIsCalled_AND_QueryIsAccessLevelString_THAN_ValidQueryDescriptionIsReturned(string query, string expectedQueryDescription)
        {
            var sandoQueryParser = new SandoQueryParser();
            var sandoQueryDescription = sandoQueryParser.Parse(query);

            Assert.IsTrue(sandoQueryDescription.IsValid);
            Assert.AreEqual(expectedQueryDescription, sandoQueryDescription.ToString());
        }
        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();
        }
Пример #3
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);
        }
Пример #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);
        }
Пример #5
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);
        }