Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnIndexHitsOrderedByRelevance() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnIndexHitsOrderedByRelevance()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(true);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Scorer = ConstantScorer(1.0f);
            collector.Collect(1);
            collector.Scorer = ConstantScorer(2.0f);
            collector.Collect(2);

            // then
            IndexHits <Document> indexHits = collector.GetIndexHits(Sort.RELEVANCE);

            assertEquals(2, indexHits.Size());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("2", indexHits.next().get("id"));
            assertEquals(2.0f, indexHits.CurrentScore(), 0.001f);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("1", indexHits.next().get("id"));
            assertEquals(1.0f, indexHits.CurrentScore(), 0.001f);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnIndexHitsInGivenSortOrder() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnIndexHitsInGivenSortOrder()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(43);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(3);
            collector.Collect(37);
            collector.Collect(42);

            // then
            Sort byIdDescending            = new Sort(new SortField("id", SortField.Type.LONG, true));
            IndexHits <Document> indexHits = collector.GetIndexHits(byIdDescending);

            assertEquals(4, indexHits.Size());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("42", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("37", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("3", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("1", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
Esempio n. 3
0
            internal virtual IDictionary <string, IDictionary <string, Serializable> > CheckIndex(GraphDatabaseService db)
            {
                IDictionary <string, IDictionary <string, Serializable> > result = new Dictionary <string, IDictionary <string, Serializable> >();

                foreach (string indexName in Db.index().nodeIndexNames())
                {
                    IDictionary <string, Serializable> thisIndex = new Dictionary <string, Serializable>();
                    Index <Node> tempIndex = Db.index().forNodes(indexName);
                    foreach (KeyValuePair <string, Serializable> property in Properties.props.SetOfKeyValuePairs())
                    {
                        using (IndexHits <Node> content = tempIndex.get(property.Key, property.Value))
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (content.hasNext())
                            {
                                foreach (Node hit in content)
                                {
                                    if (hit.Id == Id)
                                    {
                                        thisIndex[property.Key] = property.Value;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    result[indexName] = thisIndex;
                }
                return(result);
            }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode()
        public virtual void ShouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode()
        {
            RelationshipType type = MyRelTypes.TEST;
            long             startId;
            long             endId;
            Relationship     rel;

            using (Transaction tx = Db.beginTx())
            {
                Node start = Db.createNode();
                Node end   = Db.createNode();
                startId = start.Id;
                endId   = end.Id;
                rel     = start.CreateRelationshipTo(end, type);
                rel.SetProperty("Type", type.Name());
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                ReadableRelationshipIndex autoRelationshipIndex = Db.index().RelationshipAutoIndexer.AutoIndex;
                Node start = Db.getNodeById(startId);
                Node end   = Db.getNodeById(endId);
                IndexHits <Relationship> hits = autoRelationshipIndex.Get("Type", type.Name(), start, end);
                assertEquals(1, count(hits));
                assertEquals(1, hits.Size());
                rel.Delete();
                autoRelationshipIndex = Db.index().RelationshipAutoIndexer.AutoIndex;
                hits = autoRelationshipIndex.Get("Type", type.Name(), start, end);
                assertEquals(0, count(hits));
                assertEquals(0, hits.Size());
                tx.Success();
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldUseConcurrentlyCreatedNode()
        internal virtual void ShouldUseConcurrentlyCreatedNode()
        {
            // given
            GraphDatabaseService graphdb = mock(typeof(GraphDatabaseService));
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") Index<org.neo4j.graphdb.Node> index = mock(Index.class);
            Index <Node> index = mock(typeof(Index));
            Transaction  tx    = mock(typeof(Transaction));

            when(graphdb.BeginTx()).thenReturn(tx);
            when(index.GraphDatabase).thenReturn(graphdb);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") IndexHits<org.neo4j.graphdb.Node> getHits = mock(IndexHits.class);
            IndexHits <Node> getHits = mock(typeof(IndexHits));

            when(index.get("key1", "value1")).thenReturn(getHits);
            Node createdNode = mock(typeof(Node));

            when(graphdb.CreateNode()).thenReturn(createdNode);
            Node concurrentNode = mock(typeof(Node));

            when(index.PutIfAbsent(createdNode, "key1", "value1")).thenReturn(concurrentNode);
            UniqueFactory.UniqueNodeFactory unique = new UniqueNodeFactoryAnonymousInnerClass(this, index);

            // when
            UniqueEntity <Node> node = unique.GetOrCreateWithOutcome("key1", "value1");

            // then
            assertSame(node.Entity(), concurrentNode);
            assertFalse(node.WasCreated());
            verify(index).get("key1", "value1");
            verify(index).putIfAbsent(createdNode, "key1", "value1");
            verify(graphdb, times(1)).createNode();
            verify(tx).success();
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotTouchTransactionsIfAlreadyInIndex()
        internal virtual void ShouldNotTouchTransactionsIfAlreadyInIndex()
        {
            GraphDatabaseService graphdb = mock(typeof(GraphDatabaseService));
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") Index<org.neo4j.graphdb.Node> index = mock(Index.class);
            Index <Node> index = mock(typeof(Index));

            when(index.GraphDatabase).thenReturn(graphdb);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") IndexHits<org.neo4j.graphdb.Node> getHits = mock(IndexHits.class);
            IndexHits <Node> getHits = mock(typeof(IndexHits));

            when(index.get("key1", "value1")).thenReturn(getHits);
            Node indexedNode = mock(typeof(Node));

            when(getHits.Single).thenReturn(indexedNode);

            UniqueFactory.UniqueNodeFactory unique = new UniqueNodeFactoryAnonymousInnerClass4(this, index);

            // when
            Node node = unique.GetOrCreate("key1", "value1");

            // then
            assertSame(node, indexedNode);
            verify(index).get("key1", "value1");
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testDeletingNodeRemovesItFromAutoIndex()
        public virtual void TestDeletingNodeRemovesItFromAutoIndex()
        {
            NewTransaction();
            AutoIndexer <Node> nodeAutoIndexer = _graphDb.index().NodeAutoIndexer;

            nodeAutoIndexer.StartAutoIndexingProperty("foo");
            nodeAutoIndexer.Enabled = true;

            Node node1 = _graphDb.createNode();

            node1.SetProperty("foo", "bar");

            NewTransaction();

            using (IndexHits <Node> nodeIndexHits = _graphDb.index().forNodes("node_auto_index").query("_id_:*"))
            {
                assertThat(nodeIndexHits.Size(), equalTo(1));
            }

            node1.Delete();

            NewTransaction();

            using (IndexHits <Node> nodeIndexHits = _graphDb.index().forNodes("node_auto_index").query("_id_:*"))
            {
                assertThat(nodeIndexHits.Size(), equalTo(0));
            }
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowReadTransactionToSkipDeletedNodes()
        public virtual void ShouldAllowReadTransactionToSkipDeletedNodes()
        {
            // given an indexed node
            string       indexName = "index";
            Index <Node> nodeIndex;
            Node         node;
            string       key   = "key";
            string       value = "value";

            using (Transaction tx = Db.beginTx())
            {
                nodeIndex = Db.index().forNodes(indexName);
                node      = Db.createNode();
                nodeIndex.Add(node, key, value);
                tx.Success();
            }
            // delete the node, but keep it in the index
            using (Transaction tx = Db.beginTx())
            {
                node.Delete();
                tx.Success();
            }

            // when
            using (Transaction tx = Db.beginTransaction(@explicit, new SecurityContext(ANONYMOUS, READ)))
            {
                IndexHits <Node> hits = nodeIndex.get(key, value);
                // then
                assertNull(hits.Single);
            }
            // also the fact that a read-only tx can do this w/o running into permission violation is good
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createIndexWithProviderThatUsesNeoAsDataSource()
        internal virtual void CreateIndexWithProviderThatUsesNeoAsDataSource()
        {
            string indexName = "inneo";

            assertFalse(IndexExists(indexName));
            IDictionary <string, string> config = stringMap(PROVIDER, "test-dummy-neo-index", "config1", "A value", "another config", "Another value");

            Index <Node> index;

            using (Transaction transaction = _db.beginTx())
            {
                index = _db.index().forNodes(indexName, config);
                transaction.Success();
            }

            using (Transaction tx = _db.beginTx())
            {
                assertTrue(IndexExists(indexName));
                assertEquals(config, _db.index().getConfiguration(index));
                using (IndexHits <Node> indexHits = index.get("key", "something else"))
                {
                    assertEquals(0, Iterables.count(indexHits));
                }
                tx.Success();
            }

            RestartDb();

            using (Transaction tx = _db.beginTx())
            {
                assertTrue(IndexExists(indexName));
                assertEquals(config, _db.index().getConfiguration(index));
                tx.Success();
            }
        }
Esempio n. 10
0
 private static void CountNodesByKeyValue(IndexManager indexManager, string indexName, string key, string value)
 {
     using (IndexHits <Node> nodes = indexManager.ForNodes(indexName).get(key, value))
     {
         assertEquals(50, nodes.Size());
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveNonExistingRelationshipFromExplicitIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRemoveNonExistingRelationshipFromExplicitIndex()
        {
            // Given
            long relId = AddRelationshipToExplicitIndex();

            // When
            using (Transaction tx = beginTransaction())
            {
                ExplicitIndexWrite indexWrite = tx.IndexWrite();
                indexWrite.RelationshipRemoveFromExplicitIndex(INDEX_NAME, relId + 1);
                tx.Success();
            }

            // Then
            using (Org.Neo4j.Graphdb.Transaction ctx = graphDb.beginTx())
            {
                IndexHits <Relationship> hits = graphDb.index().forRelationships(INDEX_NAME).get(KEY, VALUE);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertThat(hits.next().Id, equalTo(relId));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(hits.hasNext());
                hits.Close();
                ctx.Success();
            }
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRemoveRelationshipRemovesDocument()
        public virtual void TestRemoveRelationshipRemovesDocument()
        {
            NewTransaction();
            AutoIndexer <Relationship> autoIndexer = _graphDb.index().RelationshipAutoIndexer;

            autoIndexer.StartAutoIndexingProperty("foo");
            autoIndexer.Enabled = true;

            Node         node1 = _graphDb.createNode();
            Node         node2 = _graphDb.createNode();
            Relationship rel   = node1.CreateRelationshipTo(node2, RelationshipType.withName("foo"));

            rel.SetProperty("foo", "bar");

            NewTransaction();

            using (IndexHits <Relationship> relationshipIndexHits = _graphDb.index().forRelationships("relationship_auto_index").query("_id_:*"))
            {
                assertThat(relationshipIndexHits.Size(), equalTo(1));
            }

            NewTransaction();

            rel.Delete();

            NewTransaction();

            using (IndexHits <Relationship> relationshipIndexHits = _graphDb.index().forRelationships("relationship_auto_index").query("_id_:*"))
            {
                assertThat(relationshipIndexHits.Size(), equalTo(0));
            }
        }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowReadTransactionToSkipDeletedRelationships()
        public virtual void ShouldAllowReadTransactionToSkipDeletedRelationships()
        {
            // given an indexed relationship
            string indexName = "index";
            Index <Relationship> relationshipIndex;
            Relationship         relationship;
            string key   = "key";
            string value = "value";

            using (Transaction tx = Db.beginTx())
            {
                relationshipIndex = Db.index().forRelationships(indexName);
                relationship      = Db.createNode().createRelationshipTo(Db.createNode(), MyRelTypes.TEST);
                relationshipIndex.Add(relationship, key, value);
                tx.Success();
            }
            // delete the relationship, but keep it in the index
            using (Transaction tx = Db.beginTx())
            {
                relationship.Delete();
                tx.Success();
            }

            // when
            using (Transaction tx = Db.beginTransaction(@explicit, new SecurityContext(ANONYMOUS, READ)))
            {
                IndexHits <Relationship> hits = relationshipIndex.get(key, value);
                // then
                assertNull(hits.Single);
            }
            // also the fact that a read-only tx can do this w/o running into permission violation is good
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddRelationshipToExplicitIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddRelationshipToExplicitIndex()
        {
            long relId;

            using (Org.Neo4j.Graphdb.Transaction ctx = graphDb.beginTx())
            {
                relId = graphDb.createNode().createRelationshipTo(graphDb.createNode(), RelationshipType.withName("R")).Id;
                ctx.Success();
            }

            using (Transaction tx = beginTransaction())
            {
                ExplicitIndexWrite indexWrite = tx.IndexWrite();
                indexWrite.RelationshipAddToExplicitIndex(INDEX_NAME, relId, KEY, VALUE);
                tx.Success();
            }

            // Then
            using (Org.Neo4j.Graphdb.Transaction ctx = graphDb.beginTx())
            {
                IndexHits <Relationship> hits = graphDb.index().forRelationships(INDEX_NAME).get(KEY, VALUE);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertThat(hits.next().Id, equalTo(relId));
                hits.Close();
                ctx.Success();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleRemoveNodeFromExplicitIndexTwice() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleRemoveNodeFromExplicitIndexTwice()
        {
            // Given
            long nodeId = AddNodeToExplicitIndex();

            // When
            using (Transaction tx = beginTransaction())
            {
                ExplicitIndexWrite indexWrite = tx.IndexWrite();
                indexWrite.NodeRemoveFromExplicitIndex(INDEX_NAME, nodeId);
                tx.Success();
            }

            using (Transaction tx = beginTransaction())
            {
                ExplicitIndexWrite indexWrite = tx.IndexWrite();
                indexWrite.NodeRemoveFromExplicitIndex(INDEX_NAME, nodeId);
                tx.Success();
            }

            // Then
            using (Org.Neo4j.Graphdb.Transaction ctx = graphDb.beginTx())
            {
                IndexHits <Node> hits = graphDb.index().forNodes(INDEX_NAME).get(KEY, VALUE);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(hits.hasNext());
                hits.Close();
                ctx.Success();
            }
        }
Esempio n. 16
0
        private static int SizeOf <T1>(Index <T1> index)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: try (org.neo4j.graphdb.index.IndexHits<?> indexHits = index.query("_id_:*"))
            using (IndexHits <object> indexHits = index.query("_id_:*"))
            {
                return(indexHits.Size());
            }
        }
Esempio n. 17
0
 public DocToIdIterator(IndexHits <Document> source, ICollection <EntityId> exclude, IndexReference searcherOrNull, LongSet idsModifiedInTransactionState)
 {
     this._source = source;
     this._removedInTransactionState     = exclude;
     this._searcherOrNull                = searcherOrNull;
     this._idsModifiedInTransactionState = idsModifiedInTransactionState;
     if (source.Size() == 0)
     {
         Close();
     }
 }
        private IndexHits <Node> QueryIndex(Index <Node> index)
        {
            GraphDatabaseService graphDatabaseService = DbRule.GraphDatabaseAPI;

            using (Transaction ignored = graphDatabaseService.BeginTx())
            {
                IndexHits <Node> hits = index.get("foo", 42);
                hits.Close();
                return(hits);
            }
        }
Esempio n. 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBeDeletedWhenDeletionRolledBack()
        public virtual void ShouldNotBeDeletedWhenDeletionRolledBack()
        {
            RestartTx();
            _index.delete();
            RollbackTx();
            BeginTx();
            using (IndexHits <Node> indexHits = _index.get(_key, _value))
            {
                //empty
            }
        }
Esempio n. 20
0
 private T FindSingle <T>(GraphDatabaseService db, Index <T> index, string key, string value, System.Func <IndexHits <T>, T> getter) where T : Org.Neo4j.Graphdb.PropertyContainer
 {
     using (Transaction tx = Db.beginTx())
     {
         using (IndexHits <T> hits = index.get(key, value))
         {
             T entity = getter(hits);
             tx.Success();
             return(entity);
         }
     }
 }
Esempio n. 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnEmptyIteratorWhenNoHits() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnEmptyIteratorWhenNoHits()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector(false);
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);

            // then
            IndexHits <Document> indexHits = collector.GetIndexHits(null);

            assertEquals(0, indexHits.Size());
            assertEquals(Float.NaN, indexHits.CurrentScore(), 0.001f);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
Esempio n. 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void indexDeletesShouldNotByVisibleUntilCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IndexDeletesShouldNotByVisibleUntilCommit()
        {
            CommitTx();

            WorkThread firstTx = CreateWorker("First");

            firstTx.BeginTransaction();
            firstTx.RemoveFromIndex(_key, _value);

            using (Transaction transaction = _graphDb.beginTx())
            {
                IndexHits <Node> indexHits = _index.get(_key, _value);
                assertThat(indexHits, Contains.ContainsConflict(_node));
            }

            firstTx.Rollback();
        }
 private Node Highest(string key, IndexHits <Node> query)
 {
     using (IndexHits <Node> hits = query)
     {
         long highestValue = long.MinValue;
         Node highestNode  = null;
         while (hits.MoveNext())
         {
             Node node  = hits.Current;
             long value = (( Number )node.GetProperty(key)).longValue();
             if (value > highestValue)
             {
                 highestValue = value;
                 highestNode  = node;
             }
         }
         return(highestNode);
     }
 }
Esempio n. 24
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private org.neo4j.graphdb.index.IndexHits<long> query(org.apache.lucene.search.Query query, final String key, final Object value)
        private IndexHits <long> Query(Query query, string key, object value)
        {
            IndexSearcher searcher;

            try
            {
                searcher = _searcherManager.acquire();
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
            try
            {
                DocValuesCollector collector = new DocValuesCollector(true);
                searcher.search(query, collector);
                IndexHits <Document> result        = collector.GetIndexHits(Sort.RELEVANCE);
                ExplicitIndexHits    primitiveHits = null;
                if (string.ReferenceEquals(key, null) || this._cache == null || !this._cache.ContainsKey(key))
                {
                    primitiveHits = new DocToIdIterator(result, Collections.emptyList(), null, LongSets.immutable.empty());
                }
                else
                {
                    primitiveHits = new DocToIdIteratorAnonymousInnerClass(this, result, Collections.emptyList(), LongSets.immutable.empty(), key, value);
                }
                return(WrapIndexHits(primitiveHits));
            }
            catch (IOException e)
            {
                throw new Exception(e);
            }
            finally
            {
                try
                {
                    _searcherManager.release(searcher);
                }
                catch (IOException)
                {
                }
            }
        }
Esempio n. 25
0
        public override bool MatchesSafely(IndexHits <T> indexHits)
        {
            ICollection <T> collection = Iterators.asCollection(indexHits.GetEnumerator());

            if (_expectedItems.Length != collection.Count)
            {
                _message  = "IndexHits with a size of " + _expectedItems.Length + ", got one with " + collection.Count;
                _message += collection.ToString();
                return(false);
            }

            foreach (T item in _expectedItems)
            {
                if (!collection.Contains(item))
                {
                    _message = "Item (" + item + ") not found.";
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReturnIndexHitsInIndexOrderWhenNoSortIsGiven() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal void ShouldReturnIndexHitsInIndexOrderWhenNoSortIsGiven()
        {
            // given
            DocValuesCollector collector  = new DocValuesCollector();
            IndexReaderStub    readerStub = IndexReaderWithMaxDocs(42);

            // when
            collector.DoSetNextReader(readerStub.Context);
            collector.Collect(1);
            collector.Collect(2);

            // then
            IndexHits <Document> indexHits = collector.GetIndexHits(null);

            assertEquals(2, indexHits.Size());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("1", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals("2", indexHits.next().get("id"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(indexHits.hasNext());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAddNodeToExplicitIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddNodeToExplicitIndex()
        {
            long nodeId;

            using (Transaction tx = beginTransaction())
            {
                nodeId = tx.DataWrite().nodeCreate();
                ExplicitIndexWrite indexWrite = tx.IndexWrite();
                indexWrite.NodeAddToExplicitIndex(INDEX_NAME, nodeId, KEY, VALUE);
                tx.Success();
            }

            // Then
            using (Org.Neo4j.Graphdb.Transaction ctx = graphDb.beginTx())
            {
                IndexHits <Node> hits = graphDb.index().forNodes(INDEX_NAME).get(KEY, VALUE);
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertThat(hits.next().Id, equalTo(nodeId));
                hits.Close();
                ctx.Success();
            }
        }
Esempio n. 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testForceOpenIfChanged()
        public virtual void TestForceOpenIfChanged()
        {
            // do some actions to force the indexreader to be reopened
            using (Transaction tx = _graphDb.beginTx())
            {
                Node node1 = _graphDb.getNodeById(_id1);
                Node node2 = _graphDb.getNodeById(_id2);
                Node node3 = _graphDb.getNodeById(_id3);

                node1.SetProperty("np2", "test property");

                node1.GetRelationships(RelationshipType.withName("FOO")).forEach(Relationship.delete);

                // check first node
                Relationship rel;
                using (IndexHits <Relationship> hits = RelationShipAutoIndex().get("type", "FOO", node1, node3))
                {
                    assertEquals(0, hits.Size());
                }
                // create second relation ship
                rel = node1.CreateRelationshipTo(node3, RelationshipType.withName("FOO"));
                rel.SetProperty("type", "FOO");

                // check second node -> crashs with old FullTxData
                using (IndexHits <Relationship> indexHits = RelationShipAutoIndex().get("type", "FOO", node1, node2))
                {
                    assertEquals(0, indexHits.Size());
                }
                // create second relation ship
                rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO"));
                rel.SetProperty("type", "FOO");
                using (IndexHits <Relationship> relationships = RelationShipAutoIndex().get("type", "FOO", node1, node2))
                {
                    assertEquals(1, relationships.Size());
                }

                tx.Success();
            }
        }
Esempio n. 29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void question5346011()
        public virtual void Question5346011()
        {
            GraphDatabaseService service = (new TestGraphDatabaseFactory()).newImpermanentDatabase();

            using (Transaction tx = service.BeginTx())
            {
                RelationshipIndex index = service.Index().forRelationships("exact");
                // ...creation of the nodes and relationship
                Node         node1        = service.CreateNode();
                Node         node2        = service.CreateNode();
                string       uuid         = "xyz";
                Relationship relationship = node1.CreateRelationshipTo(node2, RelationshipType.withName("related"));
                index.add(relationship, "uuid", uuid);
                // query
                using (IndexHits <Relationship> hits = index.Get("uuid", uuid, node1, node2))
                {
                    assertEquals(1, hits.Size());
                }
                tx.Success();
            }
            service.Shutdown();
        }
Esempio n. 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getSingleMustNotCloseStatementTwice()
        public virtual void getSingleMustNotCloseStatementTwice()
        {
            // given
            string indexName = "index";
            long   expected1;
            long   expected2;

            using (Transaction tx = Db.beginTx())
            {
                Node         node1     = Db.createNode();
                Node         node2     = Db.createNode();
                Index <Node> nodeIndex = Db.index().forNodes(indexName);
                nodeIndex.Add(node1, "key", "hej");
                nodeIndex.Add(node2, "key", "hejhej");

                expected1 = node1.Id;
                expected2 = node2.Id;
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                Index <Node> nodeIndex = Db.index().forNodes(indexName);

                // when using getSingle this should not close statement for outer loop
                IndexHits <Node> hits = nodeIndex.query("key", "hej");
                while (hits.MoveNext())
                {
                    Node actual1 = hits.Current;
                    assertEquals(expected1, actual1.Id);

                    IndexHits <Node> hits2   = nodeIndex.query("key", "hejhej");
                    Node             actual2 = hits2.Single;
                    assertEquals(expected2, actual2.Id);
                }
                tx.Success();
            }
        }