public static Results GetResults(Model.Domain.Search aSearch, bool aShowOfflineBots, int aStart, int aLimit, string aSort, bool aReverse) { var sort = BuildSort(aSort, aReverse); var searcher = new IndexSearcher(_writer.GetReader()); if (aSearch.Guid == Model.Domain.Search.SearchDownloads) { var query = BuildPredefinedQuery("Connected", aShowOfflineBots); return GetPredefinedResults(searcher, query, sort, aStart, aLimit); } if (aSearch.Guid == Model.Domain.Search.SearchEnabled) { var query = BuildPredefinedQuery("Enabled", aShowOfflineBots); return GetPredefinedResults(searcher, query, sort, aStart, aLimit); } var results = new Results(); var terms = GenerateTermsFromSearchString(aSearch.Name); // normal search if (terms.Count() == 1) { var query = BuildQuery(terms.First(), aSearch.Size, aShowOfflineBots); var res = GetResult(searcher, query, sort, aStart, aLimit); if (res.Total > 0) { results.Packets.Add(terms.First(), res.Packets); results.Total = res.Total; } return results; } // wildcard search var queries = BuildWildCardQueries(searcher, terms, aSearch.Size, aShowOfflineBots, aStart, aLimit); results.Total = (from query in queries select query.Total).Sum(); foreach (var query in queries) { if (!query.Enabled) { continue; } var res = GetResult(searcher, query.Query, sort, query.Start, query.Limit); if (res.Packets.Any()) { results.Packets.Add(query.Term, res.Packets); } } return results; }
static Results GetPredefinedResults(IndexSearcher aSearcher, Query aQuery, Sort aSort, int aStart, int aLimit) { var results = new Results(); var res = GetResult(aSearcher, aQuery, aSort, aStart, aLimit); results.Packets.Add("", res.Packets); results.Total = res.Total; return results; }