//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyRelationshipData(FulltextIndexProvider provider, long secondRelId) throws Exception
        private void VerifyRelationshipData(FulltextIndexProvider provider, long secondRelId)
        {
            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction   ktx    = LuceneFulltextTestSupport.KernelTransaction(tx);
                ScoreEntityIterator result = provider.Query(ktx, "fulltext", "valuuu");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(0L, result.Next().entityId());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(result.HasNext());

                result = provider.Query(ktx, "fulltext", "villa");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(secondRelId, result.Next().entityId());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(result.HasNext());

                result = provider.Query(ktx, "fulltext", "value3");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(0L, result.Next().entityId());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(secondRelId, result.Next().entityId());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(result.HasNext());
                tx.Success();
            }
        }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void raceContestantsAndVerifyResults(org.neo4j.internal.kernel.api.schema.SchemaDescriptor newDescriptor, Runnable aliceWork, Runnable changeConfig, Runnable bobWork) throws Throwable
        private void RaceContestantsAndVerifyResults(SchemaDescriptor newDescriptor, ThreadStart aliceWork, ThreadStart changeConfig, ThreadStart bobWork)
        {
            _race.addContestants(_aliceThreads, aliceWork);
            _race.addContestant(changeConfig);
            _race.addContestants(_bobThreads, bobWork);
            _race.go();
            Await(IndexDescriptorFactory.forSchema(newDescriptor, "nodes", FulltextIndexProviderFactory.Descriptor));
            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction   ktx = KernelTransaction(tx);
                ScoreEntityIterator bob = FulltextAdapter.query(ktx, "nodes", "bob");
                IList <ScoreEntityIterator.ScoreEntry> list = bob.ToList();
                try
                {
                    assertEquals(_bobThreads * _nodesCreatedPerThread, list.Count);
                }
                catch (Exception e)
                {
                    StringBuilder sb = (new StringBuilder(e.Message)).Append(Environment.NewLine).Append("Nodes found in query for bob:");
                    foreach (ScoreEntityIterator.ScoreEntry entry in list)
                    {
                        sb.Append(Environment.NewLine).Append("\t").Append(Db.getNodeById(entry.EntityId()));
                    }
                    throw e;
                }
                ScoreEntityIterator alice = FulltextAdapter.query(ktx, "nodes", "alice");
                assertEquals(0, alice.Count());
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public ScoreEntityIterator query(String query) throws org.apache.lucene.queryparser.classic.ParseException
        public override ScoreEntityIterator Query(string query)
        {
            ScoreEntityIterator iterator = _baseReader.query(query);

            iterator = iterator.Filter(entry => !_modifiedEntityIdsInThisTransaction.contains(entry.entityId()));
            iterator = mergeIterators(asList(iterator, _nearRealTimeReader.query(query)));
            return(iterator);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mergeShouldHandleAllEmptyIterators()
        public virtual void MergeShouldHandleAllEmptyIterators()
        {
            ScoreEntityIterator one   = IteratorOf(EmptyEntries());
            ScoreEntityIterator two   = IteratorOf(EmptyEntries());
            ScoreEntityIterator three = IteratorOf(EmptyEntries());

            ScoreEntityIterator concat = ScoreEntityIterator.MergeIterators(Arrays.asList(one, two, three));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(concat.HasNext());
        }
Beispiel #5
0
        public virtual Stream <RelationshipOutput> QueryFulltextForRelationships(string name, string query)
        {
            IndexReference indexReference = GetValidIndexReference(name);

            AwaitOnline(indexReference);
            EntityType entityType = indexReference.Schema().entityType();

            if (entityType != EntityType.RELATIONSHIP)
            {
                throw new System.ArgumentException("The '" + name + "' index (" + indexReference + ") is an index on " + entityType + ", so it cannot be queried for relationships.");
            }
            ScoreEntityIterator resultIterator = Accessor.query(Tx, name, query);

            return(resultIterator.Select(result => RelationshipOutput.ForExistingEntityOrNull(Db, result)).Where(Objects.nonNull));
        }
        private static void AssertQueryResultsMatch(ScoreEntityIterator result, long[] ids)
        {
            PrimitiveLongSet set = PrimitiveLongCollections.setOf(ids);

            while (result.MoveNext())
            {
                long next = result.Current.entityId();
                assertTrue(format("Result returned node id %d, expected one of %s", next, Arrays.ToString(ids)), set.Remove(next));
            }
            if (!set.Empty)
            {
                IList <long> list = new List <long>();
                set.VisitKeys(k => !list.Add(k));
                fail("Number of results differ from expected. " + set.Size() + " IDs were not found in the result: " + list);
            }
        }
        private static void AssertQueryResultsMatchInOrder(ScoreEntityIterator result, long[] ids)
        {
            int   num   = 0;
            float score = float.MaxValue;

            while (result.MoveNext())
            {
                ScoreEntityIterator.ScoreEntry scoredResult = result.Current;
                long  nextId    = scoredResult.EntityId();
                float nextScore = scoredResult.Score();
                assertThat(nextScore, lessThanOrEqualTo(score));
                score = nextScore;
                assertEquals(format("Result returned node id %d, expected %d", nextId, ids[num]), ids[num], nextId);
                num++;
            }
            assertEquals("Number of results differ from expected", ids.Length, num);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mergeShouldHandleEmptyIterators()
        public virtual void MergeShouldHandleEmptyIterators()
        {
            ScoreEntityIterator one   = IteratorOf(EmptyEntries());
            ScoreEntityIterator two   = IteratorOf(new ScoreEntry[] { Entry(1, 5), Entry(2, 4), Entry(3, 3), Entry(4, 2), Entry(5, 1) });
            ScoreEntityIterator three = IteratorOf(EmptyEntries());

            ScoreEntityIterator concat = ScoreEntityIterator.MergeIterators(Arrays.asList(one, two, three));

            for (int i = 1; i <= 5; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(concat.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                ScoreEntry entry = concat.Next();
                assertEquals(i, entry.EntityId());
                assertEquals(6 - i, entry.Score(), 0.001);
            }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(concat.HasNext());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mergeShouldReturnOrderedResults()
        public virtual void MergeShouldReturnOrderedResults()
        {
            ScoreEntityIterator one   = IteratorOf(new ScoreEntry[] { Entry(3, 10), Entry(10, 3), Entry(12, 1) });
            ScoreEntityIterator two   = IteratorOf(new ScoreEntry[] { Entry(1, 12), Entry(5, 8), Entry(7, 6), Entry(8, 5), Entry(11, 2) });
            ScoreEntityIterator three = IteratorOf(new ScoreEntry[] { Entry(2, 11), Entry(4, 9), Entry(6, 7), Entry(9, 4) });

            ScoreEntityIterator concat = ScoreEntityIterator.MergeIterators(Arrays.asList(one, two, three));

            for (int i = 1; i <= 12; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(concat.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                ScoreEntry entry = concat.Next();
                assertEquals(i, entry.EntityId());
                assertEquals(13 - i, entry.Score(), 0.001);
            }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(concat.HasNext());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyNodeData(FulltextIndexProvider provider, long thirdNodeid) throws Exception
        private void VerifyNodeData(FulltextIndexProvider provider, long thirdNodeid)
        {
            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction   ktx    = LuceneFulltextTestSupport.KernelTransaction(tx);
                ScoreEntityIterator result = provider.Query(ktx, "fulltext", "value");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(0L, result.Next().entityId());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(result.HasNext());

                result = provider.Query(ktx, "fulltext", "villa");
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(thirdNodeid, result.Next().entityId());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(result.HasNext());

                result = provider.Query(ktx, "fulltext", "value3");
                PrimitiveLongSet ids = Primitive.longSet();
                ids.Add(0L);
                ids.Add(thirdNodeid);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(ids.Remove(result.Next().entityId()));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(result.HasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(ids.Remove(result.Next().entityId()));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(result.HasNext());
                tx.Success();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void assertQueryFindsIdsInOrder(org.neo4j.kernel.api.KernelTransaction ktx, String indexName, String query, long... ids) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException, org.apache.lucene.queryparser.classic.ParseException
        internal virtual void AssertQueryFindsIdsInOrder(KernelTransaction ktx, string indexName, string query, params long[] ids)
        {
            ScoreEntityIterator result = FulltextAdapter.query(ktx, indexName, query);

            AssertQueryResultsMatchInOrder(result, ids);
        }