/// <summary>
        /// Run the Value[] from a particular entityId through the list of IndexQuery[] predicates to see if they all accept the value.
        /// </summary>
        private bool PassesFilter(long entityId, IndexQuery[] predicates)
        {
            if (predicates.Length == 1 && predicates[0] is IndexQuery.ExistsPredicate)
            {
                return(true);
            }

            Value[] values = _committedValues[entityId];
            for (int i = 0; i < values.Length; i++)
            {
                IndexQuery predicate = predicates[i];
                if (predicate.ValueGroup() == ValueGroup.GEOMETRY || predicate.ValueGroup() == ValueGroup.GEOMETRY_ARRAY || (predicate.ValueGroup() == ValueGroup.NUMBER && !TestSuite.supportFullValuePrecisionForNumbers()))
                {
                    if (!predicates[i].AcceptsValue(values[i]))
                    {
                        return(false);
                    }
                }
                // else there's no functional need to let values, other than those of GEOMETRY type, to pass through the IndexQuery filtering
                // avoiding this filtering will have testing be more strict in what index readers returns.
            }
            return(true);
        }
Beispiel #2
0
        private Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient InjectFullValuePrecision(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient cursor, IndexQuery[] query, IndexReader reader)
        {
            Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient target = cursor;
            if (!reader.HasFullValuePrecision(query))
            {
                IndexQuery[] filters = new IndexQuery[query.Length];
                int          count   = 0;
                for (int i = 0; i < query.Length; i++)
                {
                    IndexQuery q = query[i];
                    switch (q.Type())
                    {
                    case range:
                        ValueGroup valueGroup = q.ValueGroup();
                        if ((valueGroup == NUMBER || valueGroup == GEOMETRY) && !reader.HasFullValuePrecision(q))
                        {
                            filters[i] = q;
                            count++;
                        }
                        break;

                    case exact:
                        Value value = ((IndexQuery.ExactPredicate)q).value();
                        if (value.ValueGroup() == ValueGroup.NUMBER || Values.isArrayValue(value) || value.ValueGroup() == ValueGroup.GEOMETRY)
                        {
                            if (!reader.HasFullValuePrecision(q))
                            {
                                filters[i] = q;
                                count++;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
                if (count > 0)
                {
                    // filters[] can contain null elements. The non-null elements are the filters and each sit in the designated slot
                    // matching the values from the index.
                    target = new NodeValueClientFilter(target, _cursors.allocateNodeCursor(), _cursors.allocatePropertyCursor(), this, filters);
                }
            }
            return(target);
        }
Beispiel #3
0
        public override void Query(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient cursor, IndexOrder indexOrder, bool needsValues, params IndexQuery[] predicates)
        {
            if (predicates.Length != 1)
            {
                throw new System.ArgumentException("Only single property temporal indexes are supported.");
            }
            IndexQuery predicate = predicates[0];

            if (predicate is IndexQuery.ExistsPredicate)
            {
                LoadAll();
                BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(cursor, _descriptor.schema().PropertyIds);
                cursor.Initialize(_descriptor, multiProgressor, predicates, indexOrder, needsValues);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (NativeIndexReader<?,NativeIndexValue> reader : this)
                foreach (NativeIndexReader <object, NativeIndexValue> reader in this)
                {
                    reader.Query(multiProgressor, indexOrder, needsValues, predicates);
                }
            }
            else
            {
                if (ValidPredicate(predicate))
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: NativeIndexReader<?,NativeIndexValue> part = uncheckedSelect(predicate.valueGroup());
                    NativeIndexReader <object, NativeIndexValue> part = UncheckedSelect(predicate.ValueGroup());
                    if (part != null)
                    {
                        part.Query(cursor, indexOrder, needsValues, predicates);
                    }
                    else
                    {
                        cursor.Initialize(_descriptor, IndexProgressor.EMPTY, predicates, indexOrder, needsValues);
                    }
                }
                else
                {
                    cursor.Initialize(_descriptor, IndexProgressor.EMPTY, predicates, indexOrder, needsValues);
                }
            }
        }
Beispiel #4
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));
            }
        }