You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by is...@apache.org on 2017/01/26 00:54:23 UTC

lucene-solr:branch_6x: LUCENE-7659: Added IndexWriter#getFieldNames() to return all visible field names

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x cd3b795b1 -> aa467e39f


LUCENE-7659: Added IndexWriter#getFieldNames() to return all visible field names


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/aa467e39
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/aa467e39
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/aa467e39

Branch: refs/heads/branch_6x
Commit: aa467e39f04a5592e97c11c15fc936be60ad2f10
Parents: cd3b795
Author: Ishan Chattopadhyaya <is...@apache.org>
Authored: Thu Jan 26 06:07:17 2017 +0530
Committer: Ishan Chattopadhyaya <ic...@gmail.com>
Committed: Thu Jan 26 06:23:55 2017 +0530

----------------------------------------------------------------------
 lucene/CHANGES.txt                                  |  5 +++++
 .../java/org/apache/lucene/index/FieldInfos.java    |  6 ++++++
 .../java/org/apache/lucene/index/IndexWriter.java   | 16 ++++++++++++++++
 3 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa467e39/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index fcde6a2..d1bb80a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -19,6 +19,11 @@ API Changes
 * LUCENE-7643: Replaced doc-values queries in lucene/sandbox with factory
   methods on the *DocValuesField classes. (Adrien Grand)
 
+* LUCENE-7659: Added a IndexWriter#getFieldNames() method (experimental) to return
+  all field names as visible from the IndexWriter. This would be useful for
+  IndexWriter#updateDocValues() calls, to prevent calling with non-existent
+  docValues fields (Ishan Chattopadhyaya, Adrien Grand, Mike McCandless)
+
 New Features
 
 * LUCENE-7623: Add FunctionScoreQuery and FunctionMatchQuery (Alan Woodward,

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa467e39/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
index c80fb85..890dcca 100644
--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
@@ -20,8 +20,10 @@ package org.apache.lucene.index;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
@@ -324,6 +326,10 @@ public class FieldInfos implements Iterable<FieldInfo> {
       }
     }
     
+    synchronized Set<String> getFieldNames() {
+      return Collections.unmodifiableSet(new HashSet<String>(nameToNumber.keySet()));
+    }
+
     synchronized void clear() {
       numberToName.clear();
       nameToNumber.clear();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/aa467e39/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 2159d60..2e226f3 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -1783,6 +1783,22 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
     return flushDeletesCount.get();
   }
 
+  /**
+   * Return an unmodifiable set of all field names as visible
+   * from this IndexWriter, across all segments of the index.
+   * Useful for knowing which fields exist, before {@link #updateDocValues(Term, Field...)} is
+   * attempted. We could phase out this method if
+   * {@link #updateDocValues(Term, Field...)} could create the non-existent
+   * docValues fields as necessary, instead of throwing
+   * IllegalArgumentException for attempts to update non-existent
+   * docValues fields.
+   * @lucene.internal
+   * @lucene.experimental
+   */
+  public Set<String> getFieldNames() {
+    return globalFieldNumberMap.getFieldNames(); // FieldNumbers#getFieldNames() returns an unmodifiableSet
+  }
+
   final String newSegmentName() {
     // Cannot synchronize on IndexWriter because that causes
     // deadlock