public static Query GetSearchQuery(SearchControlViewModel ViewModel) { Query query = new Query(); // Get include paths foreach (var p in ViewModel.SearchPaths.Where(x => x.IsInclude && x.IsValid)) { ValidateSearchPath(p.PathValue); query.AddFileSource(new DirectorySearchSource(p.PathValue, p.IsRecursive)); } // Get exclude paths foreach (var ex in ViewModel.SearchPaths.Where(x => x.IsExclude)) { query.AddExcludePath(ex.PathValue); } // Get results file paths foreach (var rf in ViewModel.SearchPaths.Where(x => x.IsResultsFile && x.IsValid)) { query.AddFileSource(GetFileSource(rf.PathValue)); } // Get search params foreach (var f in ViewModel.SearchParams.Where(x => x.IsValid)) { query.AddFilter(QueryFilterFactory.GetQueryFilter(f)); } return(query); }
protected override IEnumerator <DeserializeRequest> Deserialize(EasyReader input) { _query = new Query(); _query.Name = input.ReadString(); _query.Subtype = input.ReadString(); _query.Exclusive = input.ReadBoolean(); // Read filters int filterCount = input.ReadInt32(); for (int i = 0; i < filterCount; i++) { var filter = Filter.GetFilterInstance(input.ReadUInt16()); if (filter == null) { continue; } filter.Deserialize(input); _query.AddFilter(filter); } // Carrier if (input.ReadBoolean()) { _query.Carrier = new Carrier(); _query.Carrier.Deserialize(input); } var complementRequest = new DeserializeRequest(); yield return(complementRequest); _query.Complement = complementRequest.Result; }
public List <FastFoods> Search(FastFoodsInputCommand command) { Query q = new Query($"(@name:{ command.Sentence })*|(@address:{ command.Sentence }*)|(@country:BR*)") .SetLanguage("portuguese"); //todo: insert this validation in model //check if exists lat, lon and radius if (!Equals(0, command.Latitude) && !Equals(0, command.Longitude) && !Equals(0, command.Kilometers)) { q.AddFilter(new Query.GeoFilter("GeoPoint", command.Longitude, command.Latitude, command.Kilometers, StackExchange.Redis.GeoUnit.Kilometers)); } var result = _client.Search(q).Documents; return(CastRedisValues <FastFoods>(result)); }
public async Task <IEnumerable <FastFoods> > SearchAsync(FastFoodsInputCommand command) { Query q = new Query($"(@Name:{ command.Sentence }*)|(@Address:{ command.Sentence }*)") .SetLanguage("portuguese"); //todo: insert this validation in model //check if exists lat, lon and radius if (!Equals(0, command.Latitude) && !Equals(0, command.Longitude) && !Equals(0, command.Kilometers)) { q.AddFilter(new Query.GeoFilter("GeoPoint", command.Longitude, command.Latitude, command.Kilometers, StackExchange.Redis.GeoUnit.Kilometers)); } var result = await _client.SearchAsync(q); var stringResponse = result.Documents; return(CastRedisValues <FastFoods>(stringResponse)); }
protected void pageLinkButton_click(object sender, EventArgs e) { LinkButton linkButton = sender as LinkButton; int pageIndex = MainUtil.GetInt(linkButton.CommandArgument, -1); pageIndex--; int startIndex = pageIndex * pageSize + 1; SearchBase searchServer; if (this.SharepointServerType == "WSS") { searchServer = new WSSSearch(SpContext); } else { searchServer = new MOSSSearch(SpContext); } string siteName = advancedSearchSitesPane.Visible ? sitesList.SelectedValue : this.Web; string listName = advancedSearchSitesPane.Visible ? listsList.SelectedValue : this.ListName; listName = (listName == Translate.Text(UIMessages.AllLists)) ? string.Empty : listName; Query searchQuery = new Query(searchBox.Text) { Range = new QueryRange { Count = pageSize, StartAt = startIndex } }; if (!string.IsNullOrEmpty(siteName) || !string.IsNullOrEmpty(listName)) { searchQuery.AddFilter(siteName, listName); } SearchResultCollection searchResultCollection = searchServer.Search(searchQuery); searchResults.DataSource = searchResultCollection; searchResults.DataBind(); }
public override IEnumerator <Parser> Parse(RantCompiler compiler, CompileContext context, TokenReader reader, Action <RST> actionCallback) { var tableName = reader.ReadLoose(R.Text, "acc-table-name"); var query = new Query(); query.Name = tableName.Value; query.Carrier = new Carrier(); query.Exclusive = reader.TakeLoose(R.Dollar); bool subtypeRead = false; bool pluralSubtypeRead = false; bool complementRead = false; bool endOfQueryReached = false; while (!reader.End && !endOfQueryReached) { var token = reader.ReadLooseToken(); switch (token.Type) { // read subtype case R.Period: if (reader.Take(R.Period)) // Plural subtype { if (pluralSubtypeRead) { compiler.SyntaxError(token, false, "err-compiler-multiple-pl-subtypes"); reader.Read(R.Text, "acc-pl-subtype-name"); break; } query.PluralSubtype = reader.Read(R.Text, "acc-pl-subtype-name").Value; pluralSubtypeRead = true; break; } // if there's already a subtype, throw an error and ignore it if (subtypeRead) { compiler.SyntaxError(token, false, "err-compiler-multiple-subtypes"); reader.Read(R.Text, "acc-subtype-name"); break; } query.Subtype = reader.Read(R.Text, "acc-subtype-name").Value; subtypeRead = true; break; // complement case R.LeftSquare: { if (complementRead) { compiler.SyntaxError(token, false, "err-compiler-multiple-complements"); } var seq = new List <RST>(); compiler.AddContext(CompileContext.QueryComplement); compiler.SetNextActionCallback(seq.Add); yield return(Get <SequenceParser>()); compiler.SetNextActionCallback(actionCallback); query.Complement = new RstSequence(seq, token.ToLocation()); complementRead = true; } break; // read class filter case R.Hyphen: { ClassFilter classFilter; if ((classFilter = query.GetClassFilters().FirstOrDefault()) == null) { classFilter = new ClassFilter(); query.AddFilter(classFilter); } var filterSwitches = new List <ClassFilterRule>(); do { reader.SkipSpace(); bool blacklist = false; // check if it's a blacklist filter if (reader.PeekType() == R.Exclamation) { blacklist = true; reader.ReadToken(); } var classFilterName = reader.Read(R.Text, "acc-class-filter-rule"); if (classFilterName.Value == null) { continue; } var rule = new ClassFilterRule(classFilterName.Value, !blacklist); filterSwitches.Add(rule); } while (reader.TakeLoose(R.Pipe)); //fyi: this feature is undocumented classFilter.AddRuleSwitch(filterSwitches.ToArray()); break; } // read regex filter case R.Without: case R.Question: { reader.SkipSpace(); bool blacklist = token.Type == R.Without; var regexFilter = reader.Read(R.Regex, "acc-regex-filter-rule"); var options = RegexOptions.Compiled | RegexOptions.ExplicitCapture; if (reader.IsNext(R.RegexFlags)) { var flagsToken = reader.ReadToken(); foreach (char flag in flagsToken.Value) { switch (flag) { case 'i': options |= RegexOptions.IgnoreCase; break; case 'm': options |= RegexOptions.Multiline; break; } } } if (regexFilter.Value == null) { break; } query.AddFilter(new RegexFilter(new Regex(regexFilter.Value, options), !blacklist)); } break; // read syllable range case R.LeftParen: // There are four possible types of values in a syllable range: // (a), (a-), (-b), (a-b) // either (a), (a-), or (a-b) if (reader.PeekLooseToken().Type == R.Text) { var firstNumberToken = reader.ReadLooseToken(); int firstNumber; if (!Util.ParseInt(firstNumberToken.Value, out firstNumber)) { compiler.SyntaxError(firstNumberToken, false, "err-compiler-bad-sylrange-value"); } // (a-) or (a-b) if (reader.PeekLooseToken().Type == R.Hyphen) { reader.ReadLooseToken(); // (a-b) if (reader.PeekLooseToken().Type == R.Text) { var secondNumberToken = reader.ReadLooseToken(); int secondNumber; if (!Util.ParseInt(secondNumberToken.Value, out secondNumber)) { compiler.SyntaxError(secondNumberToken, false, "err-compiler-bad-sylrange-value"); } query.AddFilter(new RangeFilter(firstNumber, secondNumber)); } // (a-) else { query.AddFilter(new RangeFilter(firstNumber, null)); } } // (a) else { query.AddFilter(new RangeFilter(firstNumber, firstNumber)); } } // (-b) else if (reader.PeekLooseToken().Type == R.Hyphen) { reader.ReadLooseToken(); var secondNumberToken = reader.ReadLoose(R.Text, "acc-syllable-range-value"); int secondNumber; if (!Util.ParseInt(secondNumberToken.Value, out secondNumber)) { compiler.SyntaxError(secondNumberToken, false, "err-compiler-bad-sylrange-value"); } query.AddFilter(new RangeFilter(null, secondNumber)); } // () else if (reader.PeekLooseToken().Type == R.RightParen) { compiler.SyntaxError(token, false, "err-compiler-empty-sylrange"); } // (something else) else { var errorToken = reader.ReadLooseToken(); compiler.SyntaxError(errorToken, false, "err-compiler-unknown-sylrange-token", errorToken.Value); reader.TakeAllWhile(t => !reader.IsNext(R.RightParen)); } reader.ReadLoose(R.RightParen); break; // read carriers case R.DoubleColon: ReadCarriers(reader, query.Carrier, compiler); // this should be the last part of the query, so go to the end endOfQueryReached = true; break; // end of query case R.RightAngle: endOfQueryReached = true; break; case R.Whitespace: break; default: compiler.SyntaxError(token, false, "err-compiler-unexpected-token"); break; } } if (!endOfQueryReached) { compiler.SyntaxError(reader.PrevToken, true, "err-compiler-eof"); } if (tableName.Value != null) { actionCallback(new RstQuery(query, tableName.ToLocation())); } }
public static Query <TEntity, TProjection> AsQuery <TEntity, TProjection>(this ODataQueryOptions <TEntity> options, Func <Query <TEntity, TProjection>, Query <TEntity, TProjection> > extendQuery = null, Func <string, Expression <Func <TEntity, bool> > > buildSearch = null, Action <SortProfile, Query <TEntity, TProjection> > buildSortProfile = null) where TEntity : class { var query = new Query <TEntity, TProjection>(); if (extendQuery != null) { query = extendQuery(query); } if (options != null) { if (options.Skip != null) { query.SetSkip(options.Skip.Value); } if (options.Top != null) { query.SetTake(options.Top.Value); } if (options.Filter != null) { query.AddFilter(options.Filter.ToExpression <TEntity>()); } if (options.Request.Query.ContainsKey("$search")) { if (buildSearch == null) { buildSearch = q => model => true; } var searchFilter = buildSearch(options.Request.Query["$search"]); if (searchFilter != null) { query.AddFilter(searchFilter); } } if (options.Request.Query.ContainsKey("sortProfile")) { if (buildSortProfile == null) { buildSortProfile = (sp, qry) => { }; } var raw = ((string)options.Request.Query["sortProfile"]).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var sortProfile = new SortProfile(raw[0], raw[1]); buildSortProfile(sortProfile, query); } else { if (options.OrderBy != null && options.OrderBy.OrderByClause != null) { var entityProps = typeof(TEntity).GetProperties().ToList(); foreach (var node in options.OrderBy.OrderByNodes) { var typedNode = node as OrderByPropertyNode; var prop = entityProps.FirstOrDefault(o => o.Name.ToLowerInvariant() == typedNode.Property.Name.ToLowerInvariant()); if (prop == null) { throw new ArgumentException($"Property '{typedNode.Property.Name}' not found on entity '{typeof(TEntity).Name}'"); } var param = Expression.Parameter(typeof(TEntity), "o"); var expression = Expression.Property(param, prop.Name); Expression converted = Expression.Convert(expression, typeof(object)); dynamic lambda = Expression.Lambda <Func <TEntity, object> >(converted, param); query.AddOrderBy(lambda, typedNode.OrderByClause.Direction == Microsoft.OData.UriParser.OrderByDirection.Ascending ? true : false); } } } } return(query); }
protected void searchBtn_Click(object sender, EventArgs e) { string siteName = advancedSearchSitesPane.Visible ? sitesList.SelectedValue : this.Web; string listName = advancedSearchSitesPane.Visible ? listsList.SelectedValue : this.ListName; listName = (listName == Translate.Text(UIMessages.AllLists)) ? string.Empty : listName; Query searchQuery = new Query(searchBox.Text) { Range = new QueryRange { Count = pageSize, StartAt = 1 } }; if (!string.IsNullOrEmpty(siteName) || !string.IsNullOrEmpty(listName)) { searchQuery.AddFilter(siteName, listName); } try { SearchBase searchServer; if (this.SharepointServerType == "WSS") { searchServer = new WSSSearch(SpContext); } else { searchServer = new MOSSSearch(SpContext); } SearchResultCollection searchResultCollection = searchServer.Search(searchQuery); searchResults.DataSource = searchResultCollection; if ((searchResultCollection == null) || (searchResultCollection.Count == 0)) { searchResults.HeaderTemplate = new CompiledTemplateBuilder( headerControl => headerControl.Controls.Add(new Literal { Text = Translate.Text(UIMessages.NoResultsCouldBeFoundForThisQuery) })); } searchResults.DataBind(); this.HideErrorLabel(); AttemptNumber = 0; } catch (UriFormatException ex) { errorLbl.Text = Translate.Text(UIMessages.YouDoNotHaveAccessToSharepointSearchService); ShowErrorLabel(); return; } catch (WebException ex) { errorLbl.Text = Translate.Text(UIMessages.CouldntGetResponseFromSharepointServer); HttpWebResponse webResponse = ex.Response as HttpWebResponse; if ((webResponse != null) && (webResponse.StatusCode == HttpStatusCode.Unauthorized) && (webResponse.Headers.AllKeys.Contains("WWW-Authenticate"))) { errorLbl.Text = Translate.Text(UIMessages.YouDoNotHaveEnoughRights); if (AttemptNumber < 3) { SharepointExtension.WriteAuthenticationResponseBasic(Request, Response); AttemptNumber++; } } this.ShowErrorLabel(); return; } catch (SoapException ex) { if (ex.Detail.InnerText == "ERROR_ALL_NOISE") { this.errorLbl.Text = Translate.Text(UIMessages.YourQueryIncludedOnlyCommonWordsAndOrCharactersWhichWereRemovedNoResultsAreAvailableTryToAddQueryTerms); } else { errorLbl.Text = Translate.Text(UIMessages.YouDoNotHaveAccessToSharepointSearchService); } ShowErrorLabel(); return; } }