private static string ParseNormalSearchTerms(string query, SandoQueryDescription sandoQueryDescription) { query = Regex.Replace(query, InvalidCharactersRegex, " "); //ensure non-split query terms are added too. var nonSplitTerms = query.Split(' '); foreach (var nonSplit in nonSplitTerms) { if (!String.Empty.Equals(nonSplit)) { sandoQueryDescription.SearchTerms.Add(nonSplit.Trim()); } } var wordSplitter = new WordSplitter(); var searchTerms = wordSplitter.ExtractWords(query).Where(w => !String.IsNullOrWhiteSpace(w)); foreach (var searchTerm in searchTerms) { sandoQueryDescription.SearchTerms.Add(searchTerm.Trim()); query = query.Replace(searchTerm, " "); } sandoQueryDescription.SearchTerms = sandoQueryDescription.SearchTerms.Distinct().ToList(); return(query); }
private static string ParseLocationFilters(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, LocationFilterRegex, RegexOptions.IgnoreCase); foreach (Match match in matches) { var matchedFilter = match.Groups["filter"].Value; var matchedLocation = match.Groups["location"].Value; if (!String.IsNullOrWhiteSpace(matchedLocation)) { sandoQueryDescription.Locations.Add(matchedLocation); } query = query.Replace(matchedFilter, " "); } return(query); }
private static string ParseLiteralSearchTerms(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, LiteralSearchRegex); foreach (Match match in matches) { var matchedLiteral = match.Groups["literal"].Value; var matchedLiteralContent = match.Groups["literalcontent"].Value; if (!String.IsNullOrWhiteSpace(matchedLiteralContent)) { sandoQueryDescription.LiteralSearchTerms.Add(matchedLiteral); } query = query.Replace(matchedLiteral, " "); } query = query.Replace("\"", String.Empty); return(query); }
public SandoQueryDescription Parse(string query) { var sandoQueryDescription = new SandoQueryDescription { OriginalQuery = query }; var parseFunctions = GetQueryParseFunctions(); var analyzedQuery = query; foreach (var function in parseFunctions) { if (String.IsNullOrWhiteSpace(analyzedQuery)) { return(sandoQueryDescription); } analyzedQuery = function(analyzedQuery, sandoQueryDescription); } return(sandoQueryDescription); }
private static string ParseFileExtensionFilters(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, FileExtensionFilterRegex, RegexOptions.IgnoreCase); foreach (Match match in matches) { var matchedFilter = match.Groups["filter"].Value; var matchedFileExtension = match.Groups["fileext"].Value.ToLower(); if (matchedFilter.StartsWith("-")) { sandoQueryDescription.FileExtensions.Add("-" + matchedFileExtension); } else { sandoQueryDescription.FileExtensions.Add(matchedFileExtension); } query = query.Replace(matchedFilter, " "); } return(query); }
private static string ParseProgramElementTypeFilters(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, ProgramElementTypeFilterRegex, RegexOptions.IgnoreCase); foreach (Match match in matches) { var matchedFilter = match.Groups["filter"].Value; var matchedProgramElementType = match.Groups["type"].Value.ToLower(); if (matchedFilter.StartsWith("-")) { sandoQueryDescription.ProgramElementTypes.Add("-" + matchedProgramElementType); } else { sandoQueryDescription.ProgramElementTypes.Add(matchedProgramElementType); } query = query.Replace(matchedFilter, " "); } return(query); }
private static string ParseNormalSearchTerms(string query, SandoQueryDescription sandoQueryDescription) { query = Regex.Replace(query, InvalidCharactersRegex, " "); var wordSplitter = new WordSplitter(); //add unsplit words var splitTerms = query.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string term in splitTerms) { sandoQueryDescription.SearchTerms.Add(term.Trim()); } var searchTerms = wordSplitter.ExtractWords(query).Where(w => !String.IsNullOrWhiteSpace(w)); foreach (var searchTerm in searchTerms) { sandoQueryDescription.SearchTerms.Add(searchTerm.Trim()); query = query.Replace(searchTerm, " "); } sandoQueryDescription.SearchTerms = sandoQueryDescription.SearchTerms.Distinct().ToList(); return(query); }
private static string ParseProgramElementTypeFilters(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, ProgramElementTypeFilterRegex, RegexOptions.IgnoreCase); foreach (Match match in matches) { var matchedFilter = match.Groups["filter"].Value; var matchedProgramElementType = match.Groups["type"].Value.ToLower(); if (matchedFilter.StartsWith("-")) sandoQueryDescription.ProgramElementTypes.Add("-" + matchedProgramElementType); else sandoQueryDescription.ProgramElementTypes.Add(matchedProgramElementType); query = query.Replace(matchedFilter, " "); } return query; }
private static string ParseNormalSearchTerms(string query, SandoQueryDescription sandoQueryDescription) { query = Regex.Replace(query, InvalidCharactersRegex, " "); var wordSplitter = new WordSplitter(); //add unsplit words var splitTerms = query.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string term in splitTerms) { sandoQueryDescription.SearchTerms.Add(term.Trim()); } var searchTerms = wordSplitter.ExtractWords(query).Where(w => !String.IsNullOrWhiteSpace(w) && !splitTerms.Contains("-"+w)).OrderByDescending(s => s.Length); foreach (var searchTerm in searchTerms) { sandoQueryDescription.SearchTerms.Add(searchTerm.Trim()); query = query.Replace(searchTerm, " "); } sandoQueryDescription.SearchTerms = sandoQueryDescription.SearchTerms.Distinct().ToList(); return query; }
private static string ParseLocationFilters(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, LocationFilterRegex, RegexOptions.IgnoreCase); foreach (Match match in matches) { var matchedFilter = match.Groups["filter"].Value; var matchedLocation = match.Groups["location"].Value; if (!String.IsNullOrWhiteSpace(matchedLocation)) { sandoQueryDescription.Locations.Add(matchedLocation); } query = query.Replace(matchedFilter, " "); } return query; }
private static string ParseLiteralSearchTerms(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, LiteralSearchRegex); foreach (Match match in matches) { var matchedLiteral = match.Groups["literal"].Value; var matchedLiteralContent = match.Groups["literalcontent"].Value; if (!String.IsNullOrWhiteSpace(matchedLiteralContent)) { sandoQueryDescription.LiteralSearchTerms.Add(matchedLiteral); } query = query.Replace(matchedLiteral, " "); } query = query.Replace("\"", String.Empty); return query; }
private static string ParseFileExtensionFilters(string query, SandoQueryDescription sandoQueryDescription) { var matches = Regex.Matches(query, FileExtensionFilterRegex, RegexOptions.IgnoreCase); foreach (Match match in matches) { var matchedFilter = match.Groups["filter"].Value; var matchedFileExtension = match.Groups["fileext"].Value.ToLower(); if (matchedFilter.StartsWith("-")) sandoQueryDescription.FileExtensions.Add("-" + matchedFileExtension); else sandoQueryDescription.FileExtensions.Add(matchedFileExtension); query = query.Replace(matchedFilter, " "); } return query; }
public SandoQueryDescription Parse(string query) { var sandoQueryDescription = new SandoQueryDescription {OriginalQuery = query}; var parseFunctions = GetQueryParseFunctions(); var analyzedQuery = query; foreach (var function in parseFunctions) { if (String.IsNullOrWhiteSpace(analyzedQuery)) return sandoQueryDescription; analyzedQuery = function(analyzedQuery, sandoQueryDescription); } return sandoQueryDescription; }
private static string ParseNormalSearchTerms(string query, SandoQueryDescription sandoQueryDescription) { query = Regex.Replace(query, InvalidCharactersRegex, " "); //ensure non-split query terms are added too. var nonSplitTerms = query.Split(' '); foreach (var nonSplit in nonSplitTerms) { if(!String.Empty.Equals(nonSplit)) sandoQueryDescription.SearchTerms.Add(nonSplit.Trim()); } var wordSplitter = new WordSplitter(); var searchTerms = wordSplitter.ExtractWords(query).Where(w => !String.IsNullOrWhiteSpace(w)); foreach (var searchTerm in searchTerms) { sandoQueryDescription.SearchTerms.Add(searchTerm.Trim()); query = query.Replace(searchTerm, " "); } sandoQueryDescription.SearchTerms = sandoQueryDescription.SearchTerms.Distinct().ToList(); return query; }