public override IDocumentQuery <TProjection> SelectFields <TProjection>(string[] fields) { var documentQuery = new ShardedDocumentQuery <TProjection>(theSession, getShardsToOperateOn, shardStrategy, indexName, fields, queryListeners) { pageSize = pageSize, theQueryText = new StringBuilder(theQueryText.ToString()), start = start, timeout = timeout, cutoff = cutoff, queryStats = queryStats, theWaitForNonStaleResults = theWaitForNonStaleResults, sortByHints = sortByHints, orderByFields = orderByFields, groupByFields = groupByFields, aggregationOp = aggregationOp, transformResultsFunc = transformResultsFunc, includes = new HashSet <string>(includes) }; documentQuery.AfterQueryExecuted(afterQueryExecutedCallback); return(documentQuery); }
public override IDocumentQuery <TProjection> SelectFields <TProjection>(string[] fields, string[] projections) { var documentQuery = new ShardedDocumentQuery <TProjection>(theSession, getShardsToOperateOn, shardStrategy, indexName, fields, projections, queryListeners, isMapReduce) { pageSize = pageSize, queryText = new StringBuilder(queryText.ToString()), start = start, timeout = timeout, cutoff = cutoff, cutoffEtag = cutoffEtag, queryStats = queryStats, theWaitForNonStaleResults = theWaitForNonStaleResults, theWaitForNonStaleResultsAsOfNow = theWaitForNonStaleResultsAsOfNow, sortByHints = sortByHints, orderByFields = orderByFields, isDistinct = isDistinct, allowMultipleIndexEntriesForSameDocumentToResultTransformer = allowMultipleIndexEntriesForSameDocumentToResultTransformer, transformResultsFunc = transformResultsFunc, includes = new HashSet <string>(includes), rootTypes = { typeof(T) }, beforeQueryExecutionAction = beforeQueryExecutionAction, afterQueryExecutedCallback = afterQueryExecutedCallback, afterStreamExecutedCallback = afterStreamExecutedCallback, defaultField = defaultField, highlightedFields = new List <HighlightedField>(highlightedFields), highlighterPreTags = highlighterPreTags, highlighterPostTags = highlighterPostTags, distanceErrorPct = distanceErrorPct, isSpatialQuery = isSpatialQuery, negate = negate, queryShape = queryShape, spatialFieldName = spatialFieldName, spatialRelation = spatialRelation, spatialUnits = spatialUnits, databaseCommands = databaseCommands, indexQuery = indexQuery, disableEntitiesTracking = disableEntitiesTracking, disableCaching = disableCaching, showQueryTimings = showQueryTimings, shouldExplainScores = shouldExplainScores, resultsTransformer = resultsTransformer, transformerParameters = transformerParameters, defaultOperator = defaultOperator, highlighterKeyName = highlighterKeyName, lastEquality = lastEquality }; return(documentQuery); }
public override IDocumentQuery <TProjection> SelectFields <TProjection>(string[] fields, string[] projections) { var documentQuery = new ShardedDocumentQuery <TProjection>(theSession, getShardsToOperateOn, shardStrategy, indexName, fields, projections, queryListeners, isMapReduce) { pageSize = pageSize, queryText = new StringBuilder(queryText.ToString()), start = start, timeout = timeout, cutoff = cutoff, cutoffEtag = cutoffEtag, queryStats = queryStats, theWaitForNonStaleResults = theWaitForNonStaleResults, sortByHints = sortByHints, orderByFields = orderByFields, groupByFields = groupByFields, aggregationOp = aggregationOp, transformResultsFunc = transformResultsFunc, includes = new HashSet <string>(includes), rootTypes = { typeof(T) }, beforeQueryExecutionAction = beforeQueryExecutionAction, afterQueryExecutedCallback = afterQueryExecutedCallback, defaultField = defaultField, highlightedFields = new List <HighlightedField>(highlightedFields), highlighterPreTags = highlighterPreTags, highlighterPostTags = highlighterPostTags, distanceErrorPct = distanceErrorPct, isSpatialQuery = isSpatialQuery, negate = negate, queryShape = queryShape, spatialFieldName = spatialFieldName, spatialRelation = spatialRelation, spatialUnits = spatialUnits, databaseCommands = databaseCommands, indexQuery = indexQuery, disableEntitiesTracking = disableEntitiesTracking, disableCaching = disableCaching }; return(documentQuery); }
protected override Task <QueryOperation> ExecuteActualQueryAsync() { var results = shardStrategy.ShardAccessStrategy.ApplyAsync(ShardDatabaseCommands, new ShardRequestData { EntityType = typeof(T), Query = IndexQuery, IndexName = indexName }, (commands, i) => { var queryOp = shardQueryOperations[i]; var queryContext = queryOp.EnterQueryContext(); return(commands.QueryAsync(indexName, queryOp.IndexQuery) .ContinueWith(task => { if (queryContext != null) { queryContext.Dispose(); } queryOp.EnsureIsAcceptable(task.Result); return task.Result; })); }); return(results.ContinueWith(task => { task.AssertNotFailed(); ShardedDocumentQuery <T> .AssertNoDuplicateIdsInResults(shardQueryOperations); var mergedQueryResult = shardStrategy.MergeQueryResults(IndexQuery, shardQueryOperations.Select(x => x.CurrentQueryResults).ToList()); shardQueryOperations[0].ForceResult(mergedQueryResult); queryOperation = shardQueryOperations[0]; return queryOperation; })); }
protected override Task <QueryOperation> ExecuteActualQueryAsync() { var results = CompletedTask.With(new bool[ShardDatabaseCommands.Count]).Task; Func <Task> loop = null; loop = () => { var lastResults = results.Result; results = shardStrategy.ShardAccessStrategy.ApplyAsync(ShardDatabaseCommands, new ShardRequestData { EntityType = typeof(T), Query = IndexQuery, IndexName = indexName }, (commands, i) => { if (lastResults[i]) // if we already got a good result here, do nothing { return(CompletedTask.With(true)); } var queryOp = shardQueryOperations[i]; var queryContext = queryOp.EnterQueryContext(); return(commands.QueryAsync(indexName, queryOp.IndexQuery, includes.ToArray()) .ContinueWith(task => { if (queryContext != null) { queryContext.Dispose(); } return queryOp.IsAcceptable(task.Result); })); }); return(results.ContinueWith(task => { task.AssertNotFailed(); if (lastResults.All(acceptable => acceptable)) { return new CompletedTask().Task; } Thread.Sleep(100); return loop(); }).Unwrap()); }; return(loop().ContinueWith(task => { task.AssertNotFailed(); ShardedDocumentQuery <T> .AssertNoDuplicateIdsInResults(shardQueryOperations); var mergedQueryResult = shardStrategy.MergeQueryResults(IndexQuery, shardQueryOperations.Select(x => x.CurrentQueryResults).ToList()); shardQueryOperations[0].ForceResult(mergedQueryResult); queryOperation = shardQueryOperations[0]; return queryOperation; })); }