コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.storageengine.api.schema.IndexSample sampleIndex() throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        public override IndexSample SampleIndex()
        {
            NonUniqueIndexSampler sampler     = new DefaultNonUniqueIndexSampler(_indexSamplingConfig.sampleSizeLimit());
            IndexReader           indexReader = _indexSearcher.IndexReader;

            foreach (LeafReaderContext readerContext in indexReader.leaves())
            {
                try
                {
                    ISet <string> fieldNames = GetFieldNamesToSample(readerContext);
                    foreach (string fieldName in fieldNames)
                    {
                        Terms terms = readerContext.reader().terms(fieldName);
                        if (terms != null)
                        {
                            TermsEnum termsEnum = LuceneDocumentStructure.originalTerms(terms, fieldName);
                            BytesRef  termsRef;
                            while ((termsRef = termsEnum.next()) != null)
                            {
                                sampler.Include(termsRef.utf8ToString(), termsEnum.docFreq());
                                CheckCancellation();
                            }
                        }
                    }
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }

            return(sampler.Result(indexReader.numDocs()));
        }
コード例 #2
0
        public override void Process <T1>(IndexEntryUpdate <T1> update)
        {
            long nodeId = update.EntityId;

            try
            {
                switch (update.UpdateMode())
                {
                case ADDED:
                    Added(update);
                    _writer.updateDocument(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId), LuceneDocumentStructure.documentRepresentingProperties(nodeId, update.Values()));
                    break;

                case CHANGED:
                    Changed(update);
                    _writer.updateDocument(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId), LuceneDocumentStructure.documentRepresentingProperties(nodeId, update.Values()));
                    break;

                case REMOVED:
                    Removed(update);
                    _writer.deleteDocuments(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId));
                    break;

                default:
                    throw new System.InvalidOperationException("Unknown update mode " + Arrays.ToString(update.Values()));
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void verifySearchInvocations(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher searcher, Object... values) throws java.io.IOException
        private static void VerifySearchInvocations(PartitionSearcher searcher, params object[] values)
        {
            foreach (object value in values)
            {
                verify(searcher.IndexSearcher).search(eq(LuceneDocumentStructure.newSeekQuery(Values.of(value))), any(typeof(DuplicateCheckingCollector)));
            }
        }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void verify(org.neo4j.storageengine.api.NodePropertyAccessor accessor, int[] propKeyIds, java.util.List<org.neo4j.values.storable.Value[]> updatedValueTuples) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException, java.io.IOException
        public override void Verify(NodePropertyAccessor accessor, int[] propKeyIds, IList <Value[]> updatedValueTuples)
        {
            foreach (Value[] valueTuple in updatedValueTuples)
            {
                Query query = LuceneDocumentStructure.newSeekQuery(valueTuple);
                SearchForDuplicates(query, accessor, propKeyIds);
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void doCollect(int doc) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.KernelException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        protected internal virtual void DoCollect(int doc)
        {
            Document document = Reader.document(doc);
            long     nodeId   = LuceneDocumentStructure.getNodeId(document);
            Value    value    = Accessor.getNodePropertyValue(nodeId, _propertyKeyId);

            DuplicateCheckStrategy.checkForDuplicate(value, nodeId);
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void insert(java.util.List<Object> data) throws java.io.IOException
        private void Insert(IList <object> data)
        {
            for (int i = 0; i < data.Count; i++)
            {
                Document doc = LuceneDocumentStructure.documentRepresentingProperties(i, Values.of(data[i]));
                _writer.addDocument(doc);
            }
            _searcherManager.maybeRefreshBlocking();
        }
コード例 #7
0
        protected internal override void Changed <T1>(IndexEntryUpdate <T1> update)
        {
            string encodedValueBefore = LuceneDocumentStructure.encodedStringValuesForSampling(update.BeforeValues());

            _sampler.exclude(encodedValueBefore);

            string encodedValueAfter = LuceneDocumentStructure.encodedStringValuesForSampling(update.Values());

            _sampler.include(encodedValueAfter);
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void insert(java.util.Collection<org.neo4j.values.storable.Value> data) throws java.io.IOException
        private void Insert(ICollection <Value> data)
        {
            Value[] dataArray = data.toArray(new Value[data.Count]);
            for (int i = 0; i < dataArray.Length; i++)
            {
                Document doc = LuceneDocumentStructure.documentRepresentingProperties(i, dataArray[i]);
                _index.IndexWriter.addDocument(doc);
            }
            _index.maybeRefreshBlocking();
        }
コード例 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void doCollect(int doc) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.KernelException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        protected internal override void DoCollect(int doc)
        {
            Document document = Reader.document(doc);
            long     nodeId   = LuceneDocumentStructure.getNodeId(document);

            Value[] values = new Value[_propertyKeyIds.Length];
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = Accessor.getNodePropertyValue(nodeId, _propertyKeyIds[i]);
            }
            DuplicateCheckStrategy.checkForDuplicate(values, nodeId);
        }
コード例 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void verify(org.neo4j.storageengine.api.NodePropertyAccessor accessor, int[] propKeyIds) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException, java.io.IOException
        public override void Verify(NodePropertyAccessor accessor, int[] propKeyIds)
        {
            foreach (string field in AllFields())
            {
                if (LuceneDocumentStructure.useFieldForUniquenessVerification(field))
                {
                    TermsEnum terms = LuceneDocumentStructure.originalTerms(TermsForField(field), field);
                    BytesRef  termsRef;
                    while ((termsRef = terms.next()) != null)
                    {
                        if (terms.docFreq() > 1)
                        {
                            TermQuery query = new TermQuery(new Term(field, termsRef));
                            SearchForDuplicates(query, accessor, propKeyIds, terms.docFreq());
                        }
                    }
                }
            }
        }
コード例 #11
0
        public override long CountIndexedNodes(long nodeId, int[] propertyKeyIds, params Value[] propertyValues)
        {
            Query nodeIdQuery = new TermQuery(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId));
            Query valueQuery  = LuceneDocumentStructure.newSeekQuery(propertyValues);

            BooleanQuery.Builder nodeIdAndValueQuery = (new BooleanQuery.Builder()).setDisableCoord(true);
            nodeIdAndValueQuery.add(nodeIdQuery, BooleanClause.Occur.MUST);
            nodeIdAndValueQuery.add(valueQuery, BooleanClause.Occur.MUST);
            try
            {
                TotalHitCountCollector collector = new TotalHitCountCollector();
                IndexSearcher.search(nodeIdAndValueQuery.build(), collector);
                // A <label,propertyKeyId,nodeId> tuple should only match at most a single propertyValue
                return(collector.TotalHits);
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
        }
コード例 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void verify(org.neo4j.storageengine.api.NodePropertyAccessor accessor, int[] propKeyIds, java.util.List<org.neo4j.values.storable.Value[]> updatedValueTuples) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException, java.io.IOException
        public override void Verify(NodePropertyAccessor accessor, int[] propKeyIds, IList <Value[]> updatedValueTuples)
        {
            try
            {
                DuplicateCheckingCollector collector = DuplicateCheckingCollector.ForProperties(accessor, propKeyIds);
                foreach (Value[] valueTuple in updatedValueTuples)
                {
                    collector.Init();
                    Query query = LuceneDocumentStructure.newSeekQuery(valueTuple);
                    IndexSearcher().search(query, collector);
                }
            }
            catch (IOException e)
            {
                Exception cause = e.InnerException;
                if (cause is IndexEntryConflictException)
                {
                    throw ( IndexEntryConflictException )cause;
                }
                throw e;
            }
        }
コード例 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void verify(org.neo4j.storageengine.api.NodePropertyAccessor accessor, int[] propKeyIds) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException, java.io.IOException
        public override void Verify(NodePropertyAccessor accessor, int[] propKeyIds)
        {
            try
            {
                DuplicateCheckingCollector collector = DuplicateCheckingCollector.ForProperties(accessor, propKeyIds);
                IndexSearcher searcher = IndexSearcher();
                foreach (LeafReaderContext leafReaderContext in searcher.IndexReader.leaves())
                {
                    Fields fields = leafReaderContext.reader().fields();
                    foreach (string field in fields)
                    {
                        if (LuceneDocumentStructure.useFieldForUniquenessVerification(field))
                        {
                            TermsEnum terms = LuceneDocumentStructure.originalTerms(fields.terms(field), field);
                            BytesRef  termsRef;
                            while ((termsRef = terms.next()) != null)
                            {
                                if (terms.docFreq() > 1)
                                {
                                    collector.Init(terms.docFreq());
                                    searcher.search(new TermQuery(new Term(field, termsRef)), collector);
                                }
                            }
                        }
                    }
                }
            }
            catch (IOException e)
            {
                Exception cause = e.InnerException;
                if (cause is IndexEntryConflictException)
                {
                    throw ( IndexEntryConflictException )cause;
                }
                throw e;
            }
        }
コード例 #14
0
 public static Document DocumentRepresentingProperties(long nodeId, params object[] objects)
 {
     return(LuceneDocumentStructure.documentRepresentingProperties(nodeId, Values.values(objects)));
 }
コード例 #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void insertDocument(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition partition, long nodeId, Object propertyValue) throws java.io.IOException
        private static void InsertDocument(WritableIndexPartition partition, long nodeId, object propertyValue)
        {
            Document doc = LuceneDocumentStructure.documentRepresentingProperties(nodeId, Values.of(propertyValue));

            partition.IndexWriter.addDocument(doc);
        }
コード例 #16
0
 private static Document UpdateAsDocument <T1>(IndexEntryUpdate <T1> update)
 {
     return(LuceneDocumentStructure.documentRepresentingProperties(update.EntityId, update.Values()));
 }
コード例 #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.apache.lucene.search.Query toLuceneQuery(org.neo4j.internal.kernel.api.IndexQuery... predicates) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException
        private Query ToLuceneQuery(params IndexQuery[] predicates)
        {
            IndexQuery predicate = predicates[0];

            switch (predicate.Type())
            {
            case exact:
                Value[] values = new Value[predicates.Length];
                for (int i = 0; i < predicates.Length; i++)
                {
                    Debug.Assert(predicates[i].Type() == exact, "Exact followed by another query predicate type is not supported at this moment.");
                    values[i] = ((IndexQuery.ExactPredicate)predicates[i]).value();
                }
                return(LuceneDocumentStructure.newSeekQuery(values));

            case exists:
                foreach (IndexQuery p in predicates)
                {
                    if (p.Type() != IndexQuery.IndexQueryType.exists)
                    {
                        throw new IndexNotApplicableKernelException("Exists followed by another query predicate type is not supported.");
                    }
                }
                return(LuceneDocumentStructure.newScanQuery());

            case range:
                AssertNotComposite(predicates);
                switch (predicate.ValueGroup())
                {
                case NUMBER:
                    IndexQuery.NumberRangePredicate np = (IndexQuery.NumberRangePredicate)predicate;
                    return(LuceneDocumentStructure.newInclusiveNumericRangeSeekQuery(np.From(), np.To()));

                case TEXT:
                    IndexQuery.TextRangePredicate sp = (IndexQuery.TextRangePredicate)predicate;
                    return(LuceneDocumentStructure.newRangeSeekByStringQuery(sp.From(), sp.FromInclusive(), sp.To(), sp.ToInclusive()));

                default:
                    throw new System.NotSupportedException(format("Range scans of value group %s are not supported", predicate.ValueGroup()));
                }

            case stringPrefix:
                AssertNotComposite(predicates);
                IndexQuery.StringPrefixPredicate spp = (IndexQuery.StringPrefixPredicate)predicate;
                return(LuceneDocumentStructure.newRangeSeekByPrefixQuery(spp.Prefix().stringValue()));

            case stringContains:
                AssertNotComposite(predicates);
                IndexQuery.StringContainsPredicate scp = (IndexQuery.StringContainsPredicate)predicate;
                return(LuceneDocumentStructure.newWildCardStringQuery(scp.Contains().stringValue()));

            case stringSuffix:
                AssertNotComposite(predicates);
                IndexQuery.StringSuffixPredicate ssp = (IndexQuery.StringSuffixPredicate)predicate;
                return(LuceneDocumentStructure.newSuffixStringQuery(ssp.Suffix().stringValue()));

            default:
                // todo figure out a more specific exception
                throw new Exception("Index query not supported: " + Arrays.ToString(predicates));
            }
        }
コード例 #18
0
 public override void IncludeSample <T1>(IndexEntryUpdate <T1> update)
 {
     _sampler.include(LuceneDocumentStructure.encodedStringValuesForSampling(update.Values()));
 }
コード例 #19
0
        protected internal override void Removed <T1>(IndexEntryUpdate <T1> update)
        {
            string removedValue = LuceneDocumentStructure.encodedStringValuesForSampling(update.Values());

            _sampler.exclude(removedValue);
        }
コード例 #20
0
 public static Query NewSeekQuery(params object[] objects)
 {
     return(LuceneDocumentStructure.newSeekQuery(Values.values(objects)));
 }