Beispiel #1
0
        public static IDisposable GetIdentifiersOfMappedDocuments(this Index self, string startsWith, int start, int take, out IEnumerable <string> docIds)
        {
            if (self.Type.IsMapReduce() == false)
            {
                throw new NotSupportedException("Getting doc ids for map indexes is not supported");
            }

            using (var scope = new DisposeableScope())
            {
                TransactionOperationContext indexContext;
                scope.EnsureDispose(self._contextPool.AllocateOperationContext(out indexContext));

                RavenTransaction tx;
                scope.EnsureDispose(tx = indexContext.OpenReadTransaction());

                var tree = tx.InnerTransaction.ReadTree(MapReduceIndexBase <MapReduceIndexDefinition> .MapPhaseTreeName);

                if (tree == null)
                {
                    docIds = Enumerable.Empty <string>();
                    return(scope);
                }

                TreeIterator it;
                scope.EnsureDispose(it = tree.Iterate(false));

                docIds = IterateKeys(it, startsWith, start, take, indexContext);

                return(scope.Delay());
            }
        }
Beispiel #2
0
        public static IDisposable GetReduceTree(this Index self, string docId, out IEnumerable <ReduceTree> trees)
        {
            using (var scope = new DisposeableScope())
            {
                TransactionOperationContext indexContext;
                scope.EnsureDispose(self._contextPool.AllocateOperationContext(out indexContext));

                RavenTransaction tx;
                scope.EnsureDispose(tx = indexContext.OpenReadTransaction());

                var mapPhaseTree = tx.InnerTransaction.ReadTree(MapReduceIndexBase <MapReduceIndexDefinition> .MapPhaseTreeName);

                if (mapPhaseTree == null)
                {
                    trees = Enumerable.Empty <ReduceTree>();
                    return(scope);
                }

                var reducePhaseTree = tx.InnerTransaction.ReadTree(MapReduceIndexBase <MapReduceIndexDefinition> .ReducePhaseTreeName);

                if (reducePhaseTree == null)
                {
                    trees = Enumerable.Empty <ReduceTree>();
                    return(scope);
                }

                Slice docIdAsSlice;
                scope.EnsureDispose(Slice.From(indexContext.Allocator, docId, out docIdAsSlice));

                FixedSizeTree mapEntries;
                scope.EnsureDispose(mapEntries = mapPhaseTree.FixedTreeFor(docId, sizeof(long)));

                FixedSizeTree typePerHash;
                scope.EnsureDispose(typePerHash = reducePhaseTree.FixedTreeFor(MapReduceIndexBase <MapReduceIndexDefinition> .ResultsStoreTypesTreeName, sizeof(byte)));

                trees = IterateTrees(self, mapEntries, reducePhaseTree, typePerHash, indexContext);

                return(scope.Delay());
            }
        }