You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2021/07/29 17:12:40 UTC
[lucene] 03/06: Move the version check to a final variable that is
initialized in the constructor
This is an automated email from the ASF dual-hosted git repository.
mikemccand pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit be0a3e5721ee61239e2bab67665d04a39626bd29
Author: Gautam Worah <ga...@amazon.com>
AuthorDate: Mon Jul 26 15:21:53 2021 -0700
Move the version check to a final variable that is initialized in the
constructor
---
.../directory/DirectoryTaxonomyWriter.java | 30 ++++++++++------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
index f32fa27..b3bd340 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
@@ -92,6 +92,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
private final Directory dir;
private final IndexWriter indexWriter;
+ private final boolean useOlderStoredFieldIndex;
private final TaxonomyWriterCache cache;
private final AtomicInteger cacheMisses = new AtomicInteger(0);
@@ -125,12 +126,6 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
private volatile TaxonomyIndexArrays taxoArrays;
private volatile int nextID;
- /** Reads the commit data from a Directory. */
- private static Map<String, String> readCommitData(Directory dir) throws IOException {
- SegmentInfos infos = SegmentInfos.readLatestCommit(dir);
- return infos.getUserData();
- }
-
/**
* Construct a Taxonomy writer.
*
@@ -165,9 +160,17 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
openMode = config.getOpenMode();
if (!DirectoryReader.indexExists(directory)) {
indexEpoch = 1;
+ // no commit exists so we can safely use the new BinaryDocValues field
+ useOlderStoredFieldIndex = false;
} else {
String epochStr = null;
- Map<String, String> commitData = readCommitData(directory);
+
+ SegmentInfos infos = SegmentInfos.readLatestCommit(dir);
+ /* a previous commit exists, so check the version of the last commit */
+ useOlderStoredFieldIndex =
+ !infos.getMinSegmentLuceneVersion().onOrAfter(Version.LUCENE_9_0_0);
+
+ Map<String, String> commitData = infos.getUserData();
if (commitData != null) {
epochStr = commitData.get(INDEX_EPOCH);
}
@@ -477,16 +480,11 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
String fieldPath = FacetsConfig.pathToString(categoryPath.components, categoryPath.length);
fullPathField.setStringValue(fieldPath);
- boolean commitExists = indexWriter.getLiveCommitData().iterator().hasNext();
- /* no commits so this is a fresh index, or the old index was built using a Lucene 9 or greater version */
- if ((commitExists == false)
- || (SegmentInfos.readLatestCommit(dir)
- .getMinSegmentLuceneVersion()
- .onOrAfter(Version.LUCENE_9_0_0))) {
- /* Lucene 9 introduces BinaryDocValuesField for storing taxonomy categories */
- d.add(new BinaryDocValuesField(Consts.FULL, new BytesRef(fieldPath)));
- } else {
+ if (useOlderStoredFieldIndex) {
fullPathField = new StringField(Consts.FULL, fieldPath, Field.Store.YES);
+ } else {
+ /* Lucene 9 switches to BinaryDocValuesField for storing taxonomy categories */
+ d.add(new BinaryDocValuesField(Consts.FULL, new BytesRef(fieldPath)));
}
d.add(fullPathField);