private SearchTextQuery ProcessAdvancedSearch(SearchTextQuery textQuery, SongQueryParams queryParams) { if (textQuery.IsEmpty || textQuery.MatchMode == NameMatchMode.Exact || textQuery.MatchMode == NameMatchMode.StartsWith || !textQuery.OriginalQuery.StartsWith("!")) { return(textQuery); } var parsed = SearchParser.ParseQuery(textQuery.OriginalQuery.Substring(1)); var artistNames = parsed.GetValues("artist").ToArray(); if (artistNames.Any()) { queryParams.ArtistNames = artistNames; } var words = parsed.GetValues("").ToArray(); if (words.Any()) { queryParams.Common.TextQuery = new SearchTextQuery(textQuery.Query, NameMatchMode.Words, textQuery.OriginalQuery, words); return(queryParams.Common.TextQuery); } else { return(textQuery); } }
public void ParseQuery_SpecialCharacters() { var result = SearchParser.ParseQuery("\"Dancing☆Samurai\" artist-name:Gackpoid-V2"); AssertSearchWord(result, string.Empty, "Dancing☆Samurai"); AssertSearchWord(result, "artist-name", "Gackpoid-V2"); }
public void ParseQuery_KeywordWithPhrase() { var result = SearchParser.ParseQuery("artist-name:\"Hatsune Miku\" Nostalgia"); AssertSearchWord(result, "artist-name", "Hatsune Miku"); AssertSearchWord(result, string.Empty, "Nostalgia"); }
public void TestUPnPSongArtistContains() { string text = "(upnp:class derivedfrom \"object.item.audioItem\" and (dc:creator contains \"four\" or upnp:artist contains \"five \\\" six\"))"; SearchExp exp = SearchParser.Parse(text); IList <Guid> types = new List <Guid>(); IFilter filter = SearchParser.Convert(exp, types); Console.WriteLine(text + " -> filter=" + filter + " types=[" + string.Join(",", types) + "]"); Assert.Contains(AudioAspect.ASPECT_ID, (ICollection)types, "Types"); Assert.IsTrue(filter is BooleanCombinationFilter, "Top level"); BooleanCombinationFilter topFilter = filter as BooleanCombinationFilter; Assert.AreEqual(BooleanOperator.Or, topFilter.Operator, "Top level operator"); Assert.IsTrue(topFilter.Operands is IList <IFilter>, "Top level"); IList <IFilter> operands = (IList <IFilter>)topFilter.Operands; Assert.IsTrue(operands[0] is LikeFilter, "First operand"); LikeFilter filter1 = (LikeFilter)operands[0]; Assert.AreEqual(AudioAspect.ATTR_ARTISTS, filter1.AttributeType, "Attribute"); Assert.AreEqual("%four%", filter1.Expression, "Expression"); Assert.IsTrue(operands[0] is LikeFilter, "Second operand"); LikeFilter filter2 = (LikeFilter)operands[1]; Assert.AreEqual(AudioAspect.ATTR_ARTISTS, filter2.AttributeType, "Attribute"); Assert.AreEqual("%five \" six%", filter2.Expression, "Expression"); }
public void SearchParserAndCriteriaTest() { Locator.DefaultConditionType = "Name"; var input = TestContext.DataRow["input"].ToString(); var expectedCriterionCount = Convert.ToInt32(TestContext.DataRow["expectedCount"], CultureInfo.InvariantCulture); var resultList = new List <Tuple <string, string, string> >(); for (var i = 1; i <= expectedCriterionCount; i++) { resultList.Add(new Tuple <string, string, string>( TestContext.DataRow["expectedMethod" + i].ToString(), TestContext.DataRow["expectedLocator" + i].ToString(), TestContext.DataRow["expectedGridItem" + i]?.ToString())); } var searchParser = new SearchParser(input); Assert.AreEqual(resultList.Count, searchParser.Locators.Count, "Locator count OK"); for (var i = 0; i < resultList.Count; i++) { Assert.AreEqual(resultList[i].Item1, searchParser.Locators[i].Method, "Methods OK"); Assert.AreEqual(resultList[i].Item2, searchParser.Locators[i].Criterion, "Locator OK"); Assert.AreEqual(resultList[i].Item3, searchParser.Locators[i].GridItem, "GridItem OK"); } }
private object ExecuteInternal(Expression expression) { var searchBody = SearchParser.Parse(expression); Elastic.PostSearch(connection, new PostSearchRequest { Body = searchBody }); //var translation = ElasticQueryTranslator.Translate(Mapping, Prefix, expression); //var elementType = TypeHelper.GetSequenceElementType(expression.Type); //Log.Debug(null, null, "Executing query against type {0}", elementType); //try //{ // var response = AsyncHelper.RunSync(() => requestProcessor.SearchAsync(translation.SearchRequest)); // if (response == null) // throw new InvalidOperationException("No HTTP response received."); // return translation.Materializer.Materialize(response); //} //catch (AggregateException ex) { //ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); return(null); // Never called, as the above code re-throws } }
public void SearchParserByFunctionTest() { const string locator = "abc"; var searchParser = new SearchParser("AccessibilityID", locator); Assert.AreEqual(searchParser.By, MobileBy.AccessibilityId(locator)); searchParser = new SearchParser("classname", locator); Assert.AreEqual(searchParser.By, By.ClassName(locator)); searchParser = new SearchParser("CssSelector", locator); Assert.AreEqual(searchParser.By, By.CssSelector(locator)); searchParser = new SearchParser("id", locator); Assert.AreEqual(searchParser.By, By.Id(locator)); searchParser = new SearchParser("IOSCLASSCHAIN", locator); Assert.AreEqual(searchParser.By, MobileBy.IosClassChain(locator)); searchParser = new SearchParser("iosNSpredicate", locator); Assert.AreEqual(searchParser.By, MobileBy.IosNSPredicate(locator)); searchParser = new SearchParser("IOSUIAutomation", locator); Assert.AreEqual(searchParser.By, MobileBy.IosUIAutomation(locator)); searchParser = new SearchParser("LINKTEXT", locator); Assert.AreEqual(searchParser.By, By.LinkText(locator)); searchParser = new SearchParser("NaMe", locator); Assert.AreEqual(searchParser.By, By.Name(locator)); searchParser = new SearchParser("PartialLINKTEXT", locator); Assert.AreEqual(searchParser.By, By.PartialLinkText(locator)); searchParser = new SearchParser("Tagname", locator); Assert.AreEqual(searchParser.By, By.TagName(locator)); searchParser = new SearchParser("TizenAutomation", locator); Assert.AreEqual(searchParser.By, MobileBy.TizenAutomation(locator)); searchParser = new SearchParser("WindowsAutomation", locator); Assert.AreEqual(searchParser.By, MobileBy.WindowsAutomation(locator)); searchParser = new SearchParser("XPath", locator); Assert.AreEqual(searchParser.By, By.XPath(locator)); }
public void SearchParserFindElement1Test(string input, string expectedMethod, string expectedLocator) { var searchParser = new SearchParser(input); Assert.AreEqual(expectedMethod, searchParser.Method, "Method OK"); Assert.AreEqual(expectedLocator, searchParser.Locator, "Locator OK"); }
public void ParseQuery_QueryWithKeywords() { var result = SearchParser.ParseQuery("artist-name:doriko Nostalgia"); AssertSearchWord(result, "artist-name", "doriko"); AssertSearchWord(result, string.Empty, "Nostalgia"); }
public void SearchParserFindElement2Test(string testId, string methodIn, string locatorIn, string expectedMethod, string expectedLocator) { var searchParser = new SearchParser(methodIn, locatorIn); Assert.AreEqual(expectedMethod, searchParser.Method, $"{testId} Method OK"); Assert.AreEqual(expectedLocator, searchParser.Locator, $"{testId} Locator OK"); }
public V1Controller(ILogger <V1Controller> logger, ChattyProvider chattyProvider, SearchParser searchParser, FrontPageParser frontPageParser, MessageParser messageParser) { this._logger = logger; _chattyProvider = chattyProvider; _searchParser = searchParser; _frontPageParser = frontPageParser; _messageParser = messageParser; }
public void TestUPnPImage() { string text = "upnp:class derivedfrom \"object.item.imageItem\" and @refID exists false"; SearchExp exp = SearchParser.Parse(text); IList <Guid> types = new List <Guid>(); IFilter filter = SearchParser.Convert(exp, types); Console.WriteLine(text + " -> filter=" + filter + " types=[" + string.Join(",", types) + "]"); Assert.Contains(ImageAspect.ASPECT_ID, (ICollection)types, "Types"); }
public SearchParser.ExprContext GenerateAST(string input) { var inputStream = new AntlrInputStream(input); var lexer = new SearchLexer(inputStream); var tokens = new CommonTokenStream(lexer); var parser = new SearchParser(tokens); parser.ErrorHandler = new BailErrorStrategy(); return(parser.expr()); }
public QueryPlan <Album> BuildPlan(string query) { var words = SearchParser.ParseQuery(query); var filters = new List <ISearchFilter <Album> >(); var names = words.TakeAll(string.Empty); if (names.Any()) { filters.Add(new AlbumNameFilter(names.Select(n => n.Value))); } var artists = words.TakeAll("artist"); if (artists.Any()) { filters.Add(new AlbumArtistNameFilter(artists.Select(n => n.Value))); } while (words.Any()) { var word = words.TakeNext(); ISearchFilter <Album> filter = null; switch (word.PropertyName.ToLowerInvariant()) { case "artistId": int artistId; if (int.TryParse(word.Value, out artistId)) { filter = new AlbumArtistFilter(artistId); } break; case "tag": filter = new AlbumTagFilter(word.Value); break; default: filter = new AlbumNameFilter(new[] { word.Value }); break; } if (filter != null) { filters.Add(filter); } } return(new QueryPlan <Album>(filters)); }
public void TestUPnPTitle() { string text = "(dc:title contains \"two\")"; SearchExp exp = SearchParser.Parse(text); IList <Guid> types = new List <Guid>(); IFilter filter = SearchParser.Convert(exp, types); Console.WriteLine(text + " -> filter=" + filter + " types=[" + string.Join(",", types) + "]"); Assert.IsTrue(filter is LikeFilter, "Filter"); LikeFilter filter1 = filter as LikeFilter; Assert.AreEqual(MediaAspect.ATTR_TITLE, filter1.AttributeType, "Attribute"); Assert.AreEqual("%two%", filter1.Expression, "Expression"); }
/// <summary> /// Parses the <paramref name="search"/> clause, binding /// the text into a metadata-bound list of properties to be selected using the provided model. /// </summary> /// <param name="search">String representation of the search expression from the URI.</param> /// <param name="configuration">The configuration used for binding.</param> /// <returns>A <see cref="SearchClause"/> representing the metadata bound search expression.</returns> private static SearchClause ParseSearchImplementation(string search, ODataUriParserConfiguration configuration) { ExceptionUtils.CheckArgumentNotNull(configuration, "configuration"); ExceptionUtils.CheckArgumentNotNull(search, "search"); SearchParser searchParser = new SearchParser(configuration.Settings.SearchLimit); QueryToken queryToken = searchParser.ParseSearch(search); // Bind it to metadata BindingState state = new BindingState(configuration); MetadataBinder binder = new MetadataBinder(state); SearchBinder searchBinder = new SearchBinder(binder.Bind); return(searchBinder.BindSearch(queryToken)); }
public void TestUPnPTrackContains() { string text = "(upnp:class derivedfrom \"object.item.audioItem\" and dc:title contains \"nine\")"; SearchExp exp = SearchParser.Parse(text); IList <Guid> types = new List <Guid>(); IFilter filter = SearchParser.Convert(exp, types); Console.WriteLine(text + " -> filter=" + filter + " types=[" + string.Join(",", types) + "]"); Assert.Contains(AudioAspect.ASPECT_ID, (ICollection)types, "Types"); Assert.IsTrue(filter is LikeFilter, "Filter"); LikeFilter filter1 = filter as LikeFilter; Assert.AreEqual(MediaAspect.ATTR_TITLE, filter1.AttributeType, "Attribute"); Assert.AreEqual("%nine%", filter1.Expression, "Expression"); }
IEnumerator DoSearch(string url, bool append = false) { ResultsDisplay.Instance.DisplayLoadingBar(append); using (UnityWebRequest request = UnityWebRequest.Get(url)) { List <ProgramEntry> entries = new List <ProgramEntry>(); request.SendWebRequest(); while (!request.isDone) { _progress = request.downloadProgress; yield return(new WaitForEndOfFrame()); } _progress = 1f; // Start reading the results if (request.isNetworkError || request.responseCode != 200) { Debug.Log("An error occurred: " + request.error); Debug.Log(request.downloadHandler.text); ResultsDisplay.Instance.DisplayError(string.Format("Response code {0}\nSomething went wrong! {1}\nResponse contents: {2}", request.responseCode, request.error, request.downloadHandler.text)); } else { entries = SearchParser.ParseSearch(request.downloadHandler.text); // Check if our search resulted in no results if (entries.Count == 0) { ResultsDisplay.Instance.DisplayError("No search results for '" + _lastSearch + "' :("); } else { if (entries.Count < _limit) { EndOfResults = true; } ResultsDisplay.Instance.DisplayResults(entries, append); } } } SearchInProgress = false; }
public void TestUPnPAlbumContains() { string text = "(upnp:class = \"object.container.album.musicAlbum\" and dc:title contains \"three\")"; SearchExp exp = SearchParser.Parse(text); IList <Guid> types = new List <Guid>(); IFilter filter = SearchParser.Convert(exp, types); Console.WriteLine(text + " -> filter=" + filter + " types=[" + string.Join(",", types) + "]"); Assert.Contains(AudioAspect.ASPECT_ID, (ICollection)types, "Types"); Assert.IsTrue(filter is LikeFilter, "Filter"); LikeFilter filter1 = filter as LikeFilter; Assert.AreEqual(AudioAspect.ATTR_ALBUM, filter1.AttributeType, "Attribute"); Assert.AreEqual("%three%", filter1.Expression, "Expression"); }
private void ButtonStart_Click(object sender, EventArgs e) { parser.Settings = new SearchSettings((int)NumericStart.Value, (int)NumericEnd.Value); parser.Start(); DB db = new DB(); SearchParser searchParser = new SearchParser(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand("SELECT * FROM 'prisoners' WHERE 'lastname' = @lt AND 'firstname' = @ft AND 'middlename' = @md AND 'birthday' = @bd AND 'org' = @org AND 'phone' = @ph"); command.Parameters.Add("@lt", MySqlDbType.VarChar).Value = searchParser.Equals(searchParser.item1 lastname); command.Parameters.Add("@ft", MySqlDbType.VarChar).Value = searchParser.Equals(searchParser.item2 firstname); command.Parameters.Add("@md", MySqlDbType.VarChar).Value = searchParser.Equals(searchParser.item3 middlename); command.Parameters.Add("@bd", MySqlDbType.VarChar).Value = searchParser.Equals(searchParser.item4 birthday); command.Parameters.Add("@org", MySqlDbType.VarChar).Value = searchParser.Equals(searchParser.item5 org); command.Parameters.Add("@ph", MySqlDbType.VarChar).Value = searchParser.Equals(searchParser.item6 phone); adapter.SelectCommand = command; adapter.Fill(table); }
public void Empty_ReturnsNull() { SearchParser.Parse("").ShouldBe(null); }
public void ParseQuery_QueryWithPhrase() { var result = SearchParser.ParseQuery("\"Romeo and Cinderella\""); AssertSearchWord(result, string.Empty, "Romeo and Cinderella"); }
public void ParseQuery_WordsAndPhrase() { var result = SearchParser.ParseQuery("\"Romeo and Cinderella\" Hatsune Miku"); AssertSearchWord(result, string.Empty, "Romeo and Cinderella", "Hatsune", "Miku"); }
public void LogicalNot(string searchString, bool expectation = true) { SearchParser.Parse(searchString).EvaluateOn(simpleCardText).ShouldBe(expectation); }
public void ParseQuery_MultipleWords() { var result = SearchParser.ParseQuery("Romeo and Cinderella"); AssertSearchWord(result, string.Empty, "Romeo", "and", "Cinderella"); }
public void SearchParserByFunctionNullTest() { _ = new SearchParser("unknown", "abc").By; }
public void SearchParserCustomByExceptionTest() { _ = new SearchParser("trial", "").By; }
public void SearchParserFindElement1NullTest() => _ = new SearchParser(null);
internal SearchEndPoint(HttpClient client, LoginParser authChecker, UserConfig userConfig) : base(client, authChecker) { _parser = new SearchParser(client, authChecker, userConfig); }
public void NoCardText_DoesNotMatch() { SearchParser.Parse(simpleCardText).EvaluateOn(null).ShouldBe(false); }