mirror of
https://github.com/apache/lucene.git
synced 2025-02-07 10:38:40 +00:00
LUCENE-7659: Added IndexWriter#getFieldNames() to return all visible field names
This commit is contained in:
parent
cd3b795b1f
commit
aa467e39f0
@ -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,
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user