Skip to content

Commit f25dfa5

Browse files
committed
insert lucene version on save if missing
1 parent c94877c commit f25dfa5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/nouveau/include/nouveau.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
%% limitations under the License.
1313

1414
-define(LEGACY_LUCENE_VERSION, 9).
15+
-define(TARGET_LUCENE_VERSION, 10).
1516

1617
-record(index, {
1718
dbname,

src/nouveau/src/nouveau_plugin_couch_db.erl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,44 @@
1313
-module(nouveau_plugin_couch_db).
1414

1515
-export([
16+
before_doc_update/3,
1617
is_valid_purge_client/2,
1718
on_compact/2
1819
]).
1920

21+
-include("nouveau.hrl").
22+
-include_lib("couch/include/couch_db.hrl").
23+
24+
%% New index definitions get an explicit lucene version property, if missing.
25+
before_doc_update(
26+
#doc{id = <<?DESIGN_DOC_PREFIX, _/binary>>} = Doc, Db, ?INTERACTIVE_EDIT = UpdateType
27+
) ->
28+
#doc{body = {Fields}} = Doc,
29+
case couch_util:get_value(<<"nouveau">>, Fields) of
30+
{Indexes} when is_list(Indexes) ->
31+
[add_versions_to_doc(Doc), Db, UpdateType];
32+
_ ->
33+
[Doc, Db, UpdateType]
34+
end;
35+
before_doc_update(Doc, Db, UpdateType) ->
36+
[Doc, Db, UpdateType].
37+
38+
add_versions_to_doc(#doc{} = Doc) ->
39+
#doc{body = {Fields0}} = Doc,
40+
{Indexes0} = couch_util:get_value(<<"nouveau">>, Fields0),
41+
Indexes1 = lists:map(fun add_version_to_index/1, Indexes0),
42+
Fields1 = couch_util:set_value(<<"nouveau">>, Fields0, {Indexes1}),
43+
Doc#doc{body = {Fields1}}.
44+
45+
add_version_to_index({IndexName, {Index}}) ->
46+
case couch_util:get_value(<<"lucene_version">>, Index) of
47+
undefined ->
48+
{IndexName,
49+
{couch_util:set_value(<<"lucene_version">>, Index, ?TARGET_LUCENE_VERSION)}};
50+
_ ->
51+
{IndexName, {Index}}
52+
end.
53+
2054
is_valid_purge_client(DbName, Props) ->
2155
nouveau_util:verify_index_exists(DbName, Props).
2256

0 commit comments

Comments
 (0)