Example #1
0
 internal static void AddIfAssigned(BooleanQuery.Builder builder, long node, string field)
 {
     if (node != -1)
     {
         builder.add(new TermQuery(new Term(field, "" + node)), Occur.MUST);
     }
 }
Example #2
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);
            }
        }
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.api.ExplicitIndexHits get(String key, Object valueOrNull, long startNode, long endNode) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
            public override ExplicitIndexHits Get(string key, object valueOrNull, long startNode, long endNode)
            {
                BooleanQuery.Builder builder = new BooleanQuery.Builder();
                if (!string.ReferenceEquals(key, null) && valueOrNull != null)
                {
                    builder.add(Type.get(key, valueOrNull), Occur.MUST);
                }
                AddIfAssigned(builder, startNode, KEY_START_NODE_ID);
                AddIfAssigned(builder, endNode, KEY_END_NODE_ID);
                return(Query(builder.build(), null, null, null));
            }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.api.ExplicitIndexHits query(String key, Object queryOrQueryObjectOrNull, long startNode, long endNode) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
            public override ExplicitIndexHits Query(string key, object queryOrQueryObjectOrNull, long startNode, long endNode)
            {
                QueryContext context = queryOrQueryObjectOrNull != null && queryOrQueryObjectOrNull is QueryContext ? ( QueryContext )queryOrQueryObjectOrNull : null;

                BooleanQuery.Builder builder = new BooleanQuery.Builder();
                if ((context != null && context.QueryOrQueryObject != null) || (context == null && queryOrQueryObjectOrNull != null))
                {
                    builder.add(Type.query(key, context != null ? context.QueryOrQueryObject : queryOrQueryObjectOrNull, context), Occur.MUST);
                }
                AddIfAssigned(builder, startNode, KEY_START_NODE_ID);
                AddIfAssigned(builder, endNode, KEY_END_NODE_ID);
                return(Query(builder.build(), null, null, context));
            }
Example #5
0
        private Query InjectOrphans(Query query)
        {
            if (query is BooleanQuery)
            {
                BooleanQuery         source  = ( BooleanQuery )query;
                BooleanQuery.Builder builder = new BooleanQuery.Builder();
                foreach (BooleanClause clause in source.clauses())
                {
                    builder.add(InjectOrphans(clause.Query), clause.Occur);
                }
                return(builder.build());
            }

            string orphanField = ExtractTermField(query);

            if (string.ReferenceEquals(orphanField, null))
            {
                return(query);
            }

            return((new BooleanQuery.Builder()).add(query, BooleanClause.Occur.SHOULD).add(new TermQuery(new Term(ORPHANS_KEY, orphanField)), BooleanClause.Occur.SHOULD).build());
        }