public Task <List <Guid> > SearchAsync(string queryText, SearchContext context) { var result = new List <Guid>(); if (!string.IsNullOrWhiteSpace(queryText)) { index.EnsureReader(); if (index.Searcher != null) { var query = BuildQuery(queryText, context); var hits = index.Searcher.Search(query, MaxResults).ScoreDocs; if (hits.Length > 0) { var found = new HashSet <Guid>(); foreach (var hit in hits) { if (TextIndexContent.TryGetId(hit.Doc, context.Scope, index, indexState, out var id)) { if (found.Add(id)) { result.Add(id); } } } } } } return(Task.FromResult(result)); }
public Task <List <Guid> > SearchAsync(string queryText, SearchFilter?filter, SearchContext context) { var result = new List <Guid>(); if (!string.IsNullOrWhiteSpace(queryText)) { index.EnsureReader(); if (index.Searcher != null) { var query = BuildQuery(queryText, filter, context); var hits = index.Searcher.Search(query, MaxResults).ScoreDocs; if (hits.Length > 0) { var buffer = new BytesRef(2); var found = new HashSet <Guid>(); foreach (var hit in hits) { var forValue = index.Reader.GetBinaryValue(MetaFor, hit.Doc, buffer); if (context.Scope == SearchScope.All && forValue.Bytes[0] != 1) { continue; } if (context.Scope == SearchScope.Published && forValue.Bytes[1] != 1) { continue; } var document = index.Searcher.Doc(hit.Doc); if (document != null) { var idString = document.Get(MetaContentId); if (Guid.TryParse(idString, out var id)) { if (found.Add(id)) { result.Add(id); } } } } } } } return(Task.FromResult(result)); }