Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCountDistinctValues() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCountDistinctValues()
        {
            // given
            LuceneIndexWriter writer = _index.IndexWriter;
            int expectedCount        = 10_000;

            for (int i = 0; i < expectedCount; i++)
            {
                Value value = Random.nextValue();
                writer.AddDocument(documentRepresentingProperties(i, value));
            }
            _index.maybeRefreshBlocking();

            // when/then
            GatheringNodeValueClient client           = new GatheringNodeValueClient();
            NodePropertyAccessor     propertyAccessor = mock(typeof(NodePropertyAccessor));

            using (IndexReader reader = _index.IndexReader)
            {
                reader.DistinctValues(client, propertyAccessor, true);
                int actualCount = 0;
                while (client.Progressor.next())
                {
                    actualCount += ( int )client.Reference;
                }
                assertEquals(expectedCount, actualCount);
            }
            verifyNoMoreInteractions(propertyAccessor);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetDistinctStringValues() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldGetDistinctStringValues()
        {
            // given
            LuceneIndexWriter writer = _index.IndexWriter;
            IDictionary <Value, MutableInt> expectedCounts = new Dictionary <Value, MutableInt>();

            for (int i = 0; i < 10_000; i++)
            {
                Value value = stringValue(Random.Next(1_000).ToString());
                writer.AddDocument(documentRepresentingProperties(i, value));
                expectedCounts.computeIfAbsent(value, v => new MutableInt(0)).increment();
            }
            _index.maybeRefreshBlocking();

            // when/then
            GatheringNodeValueClient client           = new GatheringNodeValueClient();
            NodePropertyAccessor     propertyAccessor = mock(typeof(NodePropertyAccessor));

            using (IndexReader reader = _index.IndexReader)
            {
                reader.DistinctValues(client, propertyAccessor, true);
                while (client.Progressor.next())
                {
                    Value      value         = client.Values[0];
                    MutableInt expectedCount = expectedCounts.Remove(value);
                    assertNotNull(expectedCount);
                    assertEquals(expectedCount.intValue(), client.Reference);
                }
                assertTrue(expectedCounts.Count == 0);
            }
            verifyNoMoreInteractions(propertyAccessor);
        }
Example #3
0
 public UniqueLuceneIndexPopulatingUpdater(LuceneIndexWriter writer, int[] propertyKeyIds, SchemaIndex luceneIndex, NodePropertyAccessor nodePropertyAccessor, UniqueIndexSampler sampler) : base(writer)
 {
     this._propertyKeyIds       = propertyKeyIds;
     this._luceneIndex          = luceneIndex;
     this._nodePropertyAccessor = nodePropertyAccessor;
     this._sampler = sampler;
 }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void changesDeliveredToIndexWriter() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ChangesDeliveredToIndexWriter()
        {
            LuceneIndexWriter writer = mock(typeof(LuceneIndexWriter));
            UniqueLuceneIndexPopulatingUpdater updater = NewUpdater(writer);

            updater.Process(change(1, _descriptor, "before1", "after1"));
            updater.Process(change(2, _descriptor, "before2", "after2"));

            verify(writer).updateDocument(newTermForChangeOrRemove(1), documentRepresentingProperties(( long )1, "after1"));
            verify(writer).updateDocument(newTermForChangeOrRemove(2), documentRepresentingProperties(( long )2, "after2"));
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void removalsDeliveredToIndexWriter() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void RemovalsDeliveredToIndexWriter()
        {
            LuceneIndexWriter writer = mock(typeof(LuceneIndexWriter));
            UniqueLuceneIndexPopulatingUpdater updater = NewUpdater(writer);

            updater.Process(remove(1, _descriptor, "foo"));
            updater.Process(remove(2, _descriptor, "bar"));
            updater.Process(remove(3, _descriptor, "baz"));

            verify(writer).deleteDocuments(newTermForChangeOrRemove(1));
            verify(writer).deleteDocuments(newTermForChangeOrRemove(2));
            verify(writer).deleteDocuments(newTermForChangeOrRemove(3));
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void additionsDeliveredToIndexWriter() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void AdditionsDeliveredToIndexWriter()
        {
            LuceneIndexWriter writer = mock(typeof(LuceneIndexWriter));
            UniqueLuceneIndexPopulatingUpdater updater = NewUpdater(writer);

            updater.Process(add(1, _descriptor, "foo"));
            updater.Process(add(2, _descriptor, "bar"));
            updater.Process(add(3, _descriptor, "qux"));

            verify(writer).updateDocument(newTermForChangeOrRemove(1), documentRepresentingProperties(( long )1, "foo"));
            verify(writer).updateDocument(newTermForChangeOrRemove(2), documentRepresentingProperties(( long )2, "bar"));
            verify(writer).updateDocument(newTermForChangeOrRemove(3), documentRepresentingProperties(( long )3, "qux"));
        }
Example #7
0
 public override void Create()
 {
     try
     {
         LuceneIndex.create();
         LuceneIndex.open();
         Writer = LuceneIndex.IndexWriter;
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Example #8
0
 private static UniqueLuceneIndexPopulatingUpdater NewUpdater(SchemaIndex index, LuceneIndexWriter writer, UniqueIndexSampler sampler)
 {
     return(new UniqueLuceneIndexPopulatingUpdater(writer, _descriptor.PropertyIds, index, mock(typeof(NodePropertyAccessor)), sampler));
 }
Example #9
0
 private static UniqueLuceneIndexPopulatingUpdater NewUpdater(LuceneIndexWriter writer)
 {
     return(NewUpdater(mock(typeof(SchemaIndex)), writer, new UniqueIndexSampler()));
 }
Example #10
0
 protected internal AbstractLuceneIndexAccessor(INDEX luceneIndex, IndexDescriptor descriptor)
 {
     this.Writer      = luceneIndex.ReadOnly ? null : luceneIndex.IndexWriter;
     this.LuceneIndex = luceneIndex;
     this.Descriptor  = descriptor;
 }