This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch import-nouveau-reorg-wip
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 030ecd9b89bd3f7ae065ffd1778575debab80f19
Author: Robert Newson <[email protected]>
AuthorDate: Sun Dec 18 10:27:58 2022 +0000

    WIP
---
 .../couchdb/nouveau/api/IndexDefinition.java       | 15 ++++++++++++-
 .../apache/couchdb/nouveau/api/LuceneVersion.java  | 25 ++++++++++++++++++++++
 src/nouveau/include/nouveau.hrl                    |  1 +
 src/nouveau/src/nouveau_index_updater.erl          |  1 +
 src/nouveau/src/nouveau_util.erl                   | 10 +++++++--
 5 files changed, 49 insertions(+), 3 deletions(-)

diff --git 
a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/IndexDefinition.java
 
b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/IndexDefinition.java
index 265a8c021..4dece3f0f 100644
--- 
a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/IndexDefinition.java
+++ 
b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/IndexDefinition.java
@@ -24,6 +24,9 @@ import io.dropwizard.jackson.JsonSnakeCase;
 @JsonSnakeCase
 public class IndexDefinition {
 
+    @NotEmpty
+    private LuceneVersion luceneVersion;
+
     @NotEmpty
     private String defaultAnalyzer;
 
@@ -34,11 +37,21 @@ public class IndexDefinition {
         // Jackson deserialization
     }
 
-    public IndexDefinition(final String defaultAnalyzer, final Map<String, 
String> fieldAnalyzers) {
+    public IndexDefinition(final LuceneVersion luceneVersion, final String 
defaultAnalyzer, final Map<String, String> fieldAnalyzers) {
+        this.luceneVersion = luceneVersion;
         this.defaultAnalyzer = defaultAnalyzer;
         this.fieldAnalyzers = fieldAnalyzers;
     }
 
+    @JsonProperty
+    public LuceneVersion getLuceneVersion() {
+        return luceneVersion;
+    }
+
+    public void setLuceneVersion(LuceneVersion luceneVersion) {
+        this.luceneVersion = luceneVersion;
+    }
+
     @JsonProperty
     public String getDefaultAnalyzer() {
         return defaultAnalyzer;
diff --git 
a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/LuceneVersion.java
 
b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/LuceneVersion.java
new file mode 100644
index 000000000..027c75902
--- /dev/null
+++ 
b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/api/LuceneVersion.java
@@ -0,0 +1,25 @@
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.couchdb.nouveau.api;
+
+public enum LuceneVersion {
+
+    // We support 4.6.1 for legacy reasons (clouseau compatibility).
+    LUCENE_4_6_1,
+
+    // We support Lucene 9, at its latest minor version, which we will
+    // update over time.
+    LUCENE_9;
+
+}
diff --git a/src/nouveau/include/nouveau.hrl b/src/nouveau/include/nouveau.hrl
index e50cd45d3..83865b312 100644
--- a/src/nouveau/include/nouveau.hrl
+++ b/src/nouveau/include/nouveau.hrl
@@ -14,6 +14,7 @@
 -record(index, {
     dbname,
     ddoc_id,
+    lucene_version,
     default_analyzer,
     field_analyzers,
     def,
diff --git a/src/nouveau/src/nouveau_index_updater.erl 
b/src/nouveau/src/nouveau_index_updater.erl
index b56ee9155..184b978d7 100644
--- a/src/nouveau/src/nouveau_index_updater.erl
+++ b/src/nouveau/src/nouveau_index_updater.erl
@@ -128,6 +128,7 @@ get_index_seq(#index{} = Index) ->
 
 index_definition(#index{} = Index) ->
     #{
+        <<"lucene_version">> => Index#index.lucene_version,
         <<"default_analyzer">> => Index#index.default_analyzer,
         <<"field_analyzers">> => Index#index.field_analyzers
     }.
diff --git a/src/nouveau/src/nouveau_util.erl b/src/nouveau/src/nouveau_util.erl
index 92bbc0113..e813e34d1 100644
--- a/src/nouveau/src/nouveau_util.erl
+++ b/src/nouveau/src/nouveau_util.erl
@@ -63,6 +63,8 @@ design_doc_to_index(DbName, #doc{id = Id, body = {Fields}}, 
IndexName) ->
         false ->
             {error, {not_found, <<IndexName/binary, " not found.">>}};
         {IndexName, {Index}} ->
+            DefaultLuceneVersion = config:get("nouveau", "lucene_version", 
"LUCENE_9"),
+            LuceneVersion = couch_util:get_value(<<"lucene_version">>, Index, 
DefaultLuceneVersion),
             DefaultAnalyzer = couch_util:get_value(<<"default_analyzer">>, 
Index, <<"standard">>),
             FieldAnalyzers = couch_util:get_value(<<"field_analyzers">>, 
Index, #{}),
             case couch_util:get_value(<<"index">>, Index) of
@@ -71,13 +73,17 @@ design_doc_to_index(DbName, #doc{id = Id, body = {Fields}}, 
IndexName) ->
                 Def ->
                     Sig = ?l2b(
                         couch_util:to_hex(
-                            couch_hash:md5_hash(
-                                term_to_binary({DefaultAnalyzer, 
FieldAnalyzers, Def})
+                            crypto:digest(
+                                sha256,
+                                term_to_binary(
+                                    {LuceneVersion, DefaultAnalyzer, 
FieldAnalyzers, Def}
+                                )
                             )
                         )
                     ),
                     {ok, #index{
                         dbname = DbName,
+                        lucene_version = LuceneVersion,
                         default_analyzer = DefaultAnalyzer,
                         field_analyzers = FieldAnalyzers,
                         ddoc_id = Id,

Reply via email to