public RemoteQueryResults Query(LinearQuery query) { var viewGenerator = queryCache.GetOrAdd(query.Query, s => new DynamicViewCompiler("query", new IndexDefinition { Map = query.Query, }, new AbstractDynamicCompilationExtension[0]) { RequiresSelectNewAnonymousType = false }.GenerateInstance()); var results = new List<string>(); var errors = new List<string>(); int lastResult = 0; int finalResult = 0; remoteStorage.Batch(actions => { var firstAndLastDocumentIds = actions.Documents.FirstAndLastDocumentIds(); finalResult = firstAndLastDocumentIds.Item2; var start = Math.Max(firstAndLastDocumentIds.Item1, query.Start); var matchingDocs = actions.Documents.DocumentsById(start, firstAndLastDocumentIds.Item2); if (string.IsNullOrEmpty(viewGenerator.ForEntityName) == false) //optimization { matchingDocs = matchingDocs.Where(x => x.Item1.Metadata.Value<string>("Raven-Entity-Name") == viewGenerator.ForEntityName); } var docs = matchingDocs .Select(x => { lastResult = x.Item2; return new DynamicJsonObject(x.Item1.ToJson()); }); var robustEnumerator = new RobustEnumerator { OnError = (exception, o) => errors.Add(String.Format("Doc '{0}', Error: {1}", Index.TryGetDocKey(o), exception.Message)) }; results.AddRange( robustEnumerator.RobustEnumeration(docs, viewGenerator.MapDefinition) .Take(query.PageSize) .Select(result => JsonExtensions.ToJObject(result).ToString()) ); }); return new RemoteQueryResults { LastScannedResult = lastResult, TotalResults = finalResult, Errors = errors.ToArray(), QueryCacheSize = queryCache.Count, Results = results.ToArray() }; }
public QueryResults ExecuteQueryUsingLinearSearch(LinearQuery query) { if (queriesAppDomain == null) { lock (this) { if (queriesAppDomain == null) InitailizeQueriesAppDomain(); } } query.PageSize = Math.Min(query.PageSize, database.Configuration.MaxPageSize); RemoteQueryResults result; using (var remoteSingleQueryRunner = queryRunnerManager.CreateSingleQueryRunner( database.TransactionalStorage.TypeForRunningQueriesInRemoteAppDomain, database.TransactionalStorage.StateForRunningQueriesInRemoteAppDomain)) { result = remoteSingleQueryRunner.Query(query); } if (result.QueryCacheSize > 1024) { lock (this) { if (queryRunnerManager.QueryCacheSize > 1024) UnloadQueriesAppDomain(); } } return new QueryResults { LastScannedResult = result.LastScannedResult, TotalResults = result.TotalResults, Errors = result.Errors, Results = result.Results.Select(JObject.Parse).ToArray() }; }
public static QueryResults ExecuteQueryUsingLinearSearch(this DocumentDatabase self,LinearQuery query) { var linearQueryRunner = (LinearQueryRunner)self.ExtensionsState.GetOrAdd(typeof(LinearQueryExtensions), o => new LinearQueryRunner(self)); return linearQueryRunner.ExecuteQueryUsingLinearSearch(query); }
public QueryResults ExecuteQueryUsingLinearSearch(LinearQuery query) { if(queriesAppDomain == null) { lock(this) { if (queriesAppDomain == null) InitailizeQueriesAppDomain(); } } query.PageSize = Math.Min(query.PageSize, Configuration.MaxPageSize); var result = queryRunner.Query(query); if(result.QueryCacheSize > 1024) { lock(this) { if(queryRunner.QueryCacheSize > 1024) UnloadQueriesAppDomain(); } } return new QueryResults { LastScannedResult = result.LastScannedResult, TotalResults = result.TotalResults, Errors = result.Errors, Results = result.Results.Select(JObject.Parse).ToArray() }; }