You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2025/08/24 20:35:32 UTC
(couchdb) 05/08: insert lucene version on save if missing
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch lucene-10
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 4176ff8103e7a14b67d0271817e8dbde2b7e9232
Author: Robert Newson <rn...@apache.org>
AuthorDate: Sat Aug 23 16:18:31 2025 +0100
insert lucene version on save if missing
---
src/nouveau/include/nouveau.hrl | 1 +
src/nouveau/src/nouveau_plugin_couch_db.erl | 34 +++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/src/nouveau/include/nouveau.hrl b/src/nouveau/include/nouveau.hrl
index 16f46bdd9..efdc6eb7e 100644
--- a/src/nouveau/include/nouveau.hrl
+++ b/src/nouveau/include/nouveau.hrl
@@ -12,6 +12,7 @@
%% limitations under the License.
-define(LEGACY_LUCENE_VERSION, 9).
+-define(TARGET_LUCENE_VERSION, 10).
-record(index, {
dbname,
diff --git a/src/nouveau/src/nouveau_plugin_couch_db.erl b/src/nouveau/src/nouveau_plugin_couch_db.erl
index dcd3ae1f1..83276ca88 100644
--- a/src/nouveau/src/nouveau_plugin_couch_db.erl
+++ b/src/nouveau/src/nouveau_plugin_couch_db.erl
@@ -13,10 +13,44 @@
-module(nouveau_plugin_couch_db).
-export([
+ before_doc_update/3,
is_valid_purge_client/2,
on_compact/2
]).
+-include("nouveau.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+%% New index definitions get an explicit lucene version property, if missing.
+before_doc_update(
+ #doc{id = <<?DESIGN_DOC_PREFIX, _/binary>>} = Doc, Db, ?INTERACTIVE_EDIT = UpdateType
+) ->
+ #doc{body = {Fields}} = Doc,
+ case couch_util:get_value(<<"nouveau">>, Fields) of
+ {Indexes} when is_list(Indexes) ->
+ [add_versions_to_doc(Doc), Db, UpdateType];
+ _ ->
+ [Doc, Db, UpdateType]
+ end;
+before_doc_update(Doc, Db, UpdateType) ->
+ [Doc, Db, UpdateType].
+
+add_versions_to_doc(#doc{} = Doc) ->
+ #doc{body = {Fields0}} = Doc,
+ {Indexes0} = couch_util:get_value(<<"nouveau">>, Fields0),
+ Indexes1 = lists:map(fun add_version_to_index/1, Indexes0),
+ Fields1 = couch_util:set_value(<<"nouveau">>, Fields0, {Indexes1}),
+ Doc#doc{body = {Fields1}}.
+
+add_version_to_index({IndexName, {Index}}) ->
+ case couch_util:get_value(<<"lucene_version">>, Index) of
+ undefined ->
+ {IndexName,
+ {couch_util:set_value(<<"lucene_version">>, Index, ?TARGET_LUCENE_VERSION)}};
+ _ ->
+ {IndexName, {Index}}
+ end.
+
is_valid_purge_client(DbName, Props) ->
nouveau_util:verify_index_exists(DbName, Props).