public bool MoveNext() { if (_initialized == false) { _start = Initialize(); } while (true) { if (_inner == null) { _inner = GetDocuments().GetEnumerator(); _innerCount = 0; } if (_inner.MoveNext() == false) { Current = null; if (_returnedResults >= _query.PageSize) { return(false); } if (_innerCount < _query.PageSize) { return(false); } _start += _query.PageSize; _inner = null; continue; } _innerCount++; var doc = _fieldsToFetch.IsProjection ? MapQueryResultRetriever.GetProjectionFromDocument(_inner.Current, 0f, _fieldsToFetch, _context) : _inner.Current; if (_query.SkipDuplicateChecking || _fieldsToFetch.IsDistinct == false) { _returnedResults++; Current = doc; return(true); } if (_alreadySeenProjections.Add(doc.DataHash)) { _returnedResults++; Current = doc; return(true); } if (_returnedResults >= _query.PageSize) { return(false); } } }
public RetrieveDocumentIdsVisitor(MapQueryResultRetriever resultsRetriever, QueryMetadata metadata, ByteStringContext allocator) : base(metadata.Query.QueryText) { _query = metadata.Query; _resultsRetriever = resultsRetriever; _metadata = metadata; _allocator = allocator; }
public Enumerator(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, Reference <int> totalResults) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _context = context; _totalResults = totalResults; _totalResults.Value = 0; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _ids = ExtractIdsFromQuery(query); if (_ids != null && _ids.Count > BooleanQuery.MaxClauseCount) { throw new BooleanQuery.TooManyClauses(); } _sort = ExtractSortFromQuery(query); _resultsRetriever = new MapQueryResultRetriever(database, query, documents, context, fieldsToFetch, includeDocumentsCommand); }
public Enumerator(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, QueryTimingsScope queryTimings, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, IncludeCompareExchangeValuesCommand includeCompareExchangeValuesCommand, Reference <int> totalResults, long?queryOperationInternalStart, DocumentFields fields) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _context = context; _totalResults = totalResults; _totalResults.Value = 0; _queryOperationInternalStart = queryOperationInternalStart; _fields = fields; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _resultsRetriever = new MapQueryResultRetriever(database, query, queryTimings, documents, context, fieldsToFetch, includeDocumentsCommand, includeCompareExchangeValuesCommand); (_ids, _startsWith) = ExtractIdsFromQuery(query, context); }
private int Initialize() { _initialized = true; if (_query.Start == 0) { return(0); } if (_query.SkipDuplicateChecking) { return(_query.Start); } if (_fieldsToFetch.IsDistinct == false) { return(_query.Start); } var start = 0; while (true) { var count = 0; foreach (var document in ApplySorting(_documents.GetDocumentsFrom(_context, _collection, 0, start, _query.PageSize))) { count++; var doc = _fieldsToFetch.IsProjection ? MapQueryResultRetriever.GetProjectionFromDocument(document, 0f, _fieldsToFetch, _context) : _inner.Current; if (doc.Data.Count <= 0) { continue; } if (_alreadySeenProjections.Add(doc.DataHash) && _alreadySeenProjections.Count == _query.Start) { break; } } if (_alreadySeenProjections.Count == _query.Start) { break; } if (count < _query.PageSize) { break; } start += count; } return(start); }
public Enumerator(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, QueryTimingsScope queryTimings, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, IncludeRevisionsCommand includeRevisionsCommand, IncludeCompareExchangeValuesCommand includeCompareExchangeValuesCommand, Reference <int> totalResults, Reference <int> scannedResults, string startAfterId, Reference <long> alreadySeenIdsCount, DocumentFields fields, Reference <long> skippedResults, CancellationToken token) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _queryTimings = queryTimings; _context = context; _totalResults = totalResults; _scannedResults = scannedResults; _totalResults.Value = 0; _startAfterId = startAfterId; _alreadySeenIdsCount = alreadySeenIdsCount; _fields = fields; _skippedResults = skippedResults; _token = token; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _resultsRetriever = new MapQueryResultRetriever(database, query, queryTimings, documents, context, fieldsToFetch, includeDocumentsCommand, includeCompareExchangeValuesCommand, includeRevisionsCommand); (_ids, _startsWith) = ExtractIdsFromQuery(query, context); if (_query.Metadata.FilterScript != null) { var key = new FilterKey(_query.Metadata); _releaseFilterScriptRunner = database.Scripts.GetScriptRunner(key, readOnly: true, patchRun: out _filterScriptRun); } }
private (List <Slice>, string) ExtractIdsFromQuery(IndexQueryServerSide query, MapQueryResultRetriever resultsRetriever) { if (string.IsNullOrWhiteSpace(query.Query)) { return(null, null); } if (query.Metadata.Query.Where == null) { return(null, null); } if (query.Metadata.IndexFieldNames.Contains(QueryFieldName.DocumentId) == false) { return(null, null); } var idsRetriever = new RetrieveDocumentIdsVisitor(resultsRetriever, query.Metadata, _context.Allocator); idsRetriever.Visit(query.Metadata.Query.Where, query.QueryParameters); return(idsRetriever.Ids.OrderBy(x => x, SliceComparer.Instance).ToList(), idsRetriever.StartsWith); }