You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/01/21 21:27:05 UTC

[GitHub] [lucene-solr] orenovadia opened a new pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

orenovadia opened a new pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231


   https://issues.apache.org/jira/browse/LUCENE-9680
   
   # Description
   
   As discussed in [this thread](http://mail-archives.apache.org/mod_mbox/lucene-dev/202101.mbox/browser), the `indexWriter::getFieldNames()` method is useful for enforcing soft/hard limits of index usage. 
   
   `getFieldNames()` was recently removed in [LUCENE-8909](https://issues.apache.org/jira/browse/LUCENE-8909).
   
   # Tests
   
   Added a unit test on `IndexWriter`
   
   # Checklist
   
   Please review the following and check all that apply:
   
   - [x] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
   - [x] I have created a Jira issue and added the issue ID to my pull request title.
   - [ ] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
   - [x] I have developed this patch against the `master` branch.
   - [x] I have run `./gradlew check`.
   - [x] I have added tests for my changes.
   - [ ] I have added documentation for the [Ref Guide](https://github.com/apache/lucene-solr/tree/master/solr/solr-ref-guide) (for Solr changes only).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] msokolov merged pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
msokolov merged pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] orenovadia commented on a change in pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
orenovadia commented on a change in pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231#discussion_r568890937



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -4600,4 +4600,49 @@ public void testIndexWriterBlocksOnStall() throws IOException, InterruptedExcept
       }
     }
   }
+
+  public void testGetFieldNames() throws IOException {
+    Directory dir = newDirectory();
+
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+
+    assertEquals(Set.of(), writer.getFieldNames());
+
+    addDocWithField(writer, "f1");
+    assertEquals(Set.of("f1"), writer.getFieldNames());
+
+    // should be unmodifiable:
+    final Set<String> fieldSet = writer.getFieldNames();
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.add("cannot modify"));
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.remove("f1"));
+
+    addDocWithField(writer, "f2");
+    assertEquals(Set.of("f1", "f2"), writer.getFieldNames());

Review comment:
       Sounds good!
   Added in: 1bc95ae7f7e




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] orenovadia commented on a change in pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
orenovadia commented on a change in pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231#discussion_r568890937



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -4600,4 +4600,49 @@ public void testIndexWriterBlocksOnStall() throws IOException, InterruptedExcept
       }
     }
   }
+
+  public void testGetFieldNames() throws IOException {
+    Directory dir = newDirectory();
+
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+
+    assertEquals(Set.of(), writer.getFieldNames());
+
+    addDocWithField(writer, "f1");
+    assertEquals(Set.of("f1"), writer.getFieldNames());
+
+    // should be unmodifiable:
+    final Set<String> fieldSet = writer.getFieldNames();
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.add("cannot modify"));
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.remove("f1"));
+
+    addDocWithField(writer, "f2");
+    assertEquals(Set.of("f1", "f2"), writer.getFieldNames());

Review comment:
       Sounds good!
   Added in: 1bc95ae7f7e




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] msokolov commented on a change in pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231#discussion_r568979069



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -4600,4 +4600,49 @@ public void testIndexWriterBlocksOnStall() throws IOException, InterruptedExcept
       }
     }
   }
+
+  public void testGetFieldNames() throws IOException {
+    Directory dir = newDirectory();
+
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+
+    assertEquals(Set.of(), writer.getFieldNames());
+
+    addDocWithField(writer, "f1");
+    assertEquals(Set.of("f1"), writer.getFieldNames());
+
+    // should be unmodifiable:
+    final Set<String> fieldSet = writer.getFieldNames();
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.add("cannot modify"));
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.remove("f1"));
+
+    addDocWithField(writer, "f2");
+    assertEquals(Set.of("f1", "f2"), writer.getFieldNames());

Review comment:
       thanks, @orenovadia !




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] orenovadia commented on pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
orenovadia commented on pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231#issuecomment-772872822


   Thank you!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] msokolov commented on a change in pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231#discussion_r568979069



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -4600,4 +4600,49 @@ public void testIndexWriterBlocksOnStall() throws IOException, InterruptedExcept
       }
     }
   }
+
+  public void testGetFieldNames() throws IOException {
+    Directory dir = newDirectory();
+
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+
+    assertEquals(Set.of(), writer.getFieldNames());
+
+    addDocWithField(writer, "f1");
+    assertEquals(Set.of("f1"), writer.getFieldNames());
+
+    // should be unmodifiable:
+    final Set<String> fieldSet = writer.getFieldNames();
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.add("cannot modify"));
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.remove("f1"));
+
+    addDocWithField(writer, "f2");
+    assertEquals(Set.of("f1", "f2"), writer.getFieldNames());

Review comment:
       thanks, @orenovadia !




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] msokolov merged pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
msokolov merged pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


[GitHub] [lucene-solr] msokolov commented on a change in pull request #2231: LUCENE-9680 - Re-add IndexWriter::getFieldNames

Posted by GitBox <gi...@apache.org>.
msokolov commented on a change in pull request #2231:
URL: https://github.com/apache/lucene-solr/pull/2231#discussion_r568105107



##########
File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
##########
@@ -4600,4 +4600,49 @@ public void testIndexWriterBlocksOnStall() throws IOException, InterruptedExcept
       }
     }
   }
+
+  public void testGetFieldNames() throws IOException {
+    Directory dir = newDirectory();
+
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+
+    assertEquals(Set.of(), writer.getFieldNames());
+
+    addDocWithField(writer, "f1");
+    assertEquals(Set.of("f1"), writer.getFieldNames());
+
+    // should be unmodifiable:
+    final Set<String> fieldSet = writer.getFieldNames();
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.add("cannot modify"));
+    assertThrows(UnsupportedOperationException.class, () -> fieldSet.remove("f1"));
+
+    addDocWithField(writer, "f2");
+    assertEquals(Set.of("f1", "f2"), writer.getFieldNames());

Review comment:
       Let's also assert that the original `fieldSet` has not been modified - it was a true copy and not some kind of alias over an underlying modifiable Set?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org