Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/full text search #1136

Merged
merged 13 commits into from
Feb 20, 2017
3 changes: 2 additions & 1 deletion apps/ejabberd/priv/mysql-part-muc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CREATE TABLE mam_muc_message_00(
-- A nick of the message's originator
nick_name varchar(250) NOT NULL,
-- Term-encoded message packet
message blob NOT NULL
message blob NOT NULL,
search_body text
) ENGINE=InnoDB;
CREATE INDEX i_mam_muc_message_room_name_added_at USING BTREE ON mam_muc_message_00(room_id, id);

Expand Down
1 change: 1 addition & 0 deletions apps/ejabberd/priv/mysql-part.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CREATE TABLE mam_message_00(
direction ENUM('I','O') NOT NULL,
-- Term-encoded message packet
message blob NOT NULL,
search_body text,
PRIMARY KEY (user_id, id),
INDEX i_mam_message_rem USING BTREE (user_id, remote_bare_jid, id)
) ENGINE=InnoDB;
Expand Down
6 changes: 6 additions & 0 deletions apps/ejabberd/priv/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ CREATE TABLE roster_version (
-- UPDATE rosterusers SET askmessage = '';
-- ALTER TABLE rosterusers ALTER COLUMN askmessage SET NOT NULL;
--
-- To update from 2.0.0:
-- ALTER TABLE mam_message ADD COLUMN search_body text;
-- ALTER TABLE mam_muc_message ADD COLUMN search_body text;
--
-- NOTE: A "minified" JID is an encoded form of JID storing only
-- the difference between a user's JID and the real JID.
-- Consult with mod_mam_utils:jid_to_opt_binary/2
Expand Down Expand Up @@ -205,6 +209,7 @@ CREATE TABLE mam_message(
-- Term-encoded message packet
-- Don't try to decode it using MySQL tools
message blob NOT NULL,
search_body text,
PRIMARY KEY (user_id, id),
INDEX i_mam_message_rem USING BTREE (user_id, remote_bare_jid, id)
) ENGINE=InnoDB
Expand Down Expand Up @@ -243,6 +248,7 @@ CREATE TABLE mam_muc_message(
nick_name varchar(250) NOT NULL,
-- Term-encoded message packet
message blob NOT NULL,
search_body text,
PRIMARY KEY (room_id, id)
);

Expand Down
6 changes: 6 additions & 0 deletions apps/ejabberd/priv/pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ CREATE TABLE roster_version (
-- UPDATE rosterusers SET askmessage = '';
-- ALTER TABLE rosterusers ALTER COLUMN askmessage SET NOT NULL;

-- To update from 2.0.0:
-- ALTER TABLE mam_message ADD COLUMN search_body text;
-- ALTER TABLE mam_muc_message ADD COLUMN search_body text;

CREATE TYPE mam_behaviour AS ENUM('A', 'N', 'R');
CREATE TYPE mam_direction AS ENUM('I','O');

Expand All @@ -186,6 +190,7 @@ CREATE TABLE mam_message(
direction mam_direction NOT NULL,
-- Term-encoded message packet
message bytea NOT NULL,
search_body text,
PRIMARY KEY(user_id, id)
);
CREATE INDEX i_mam_message_username_jid_id
Expand Down Expand Up @@ -224,6 +229,7 @@ CREATE TABLE mam_muc_message(
nick_name varchar(250) NOT NULL,
-- Term-encoded message packet
message bytea NOT NULL,
search_body text,
PRIMARY KEY (room_id, id)
);

Expand Down
49 changes: 27 additions & 22 deletions apps/ejabberd/src/ejabberd_gen_mam_archive.erl
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
-module(ejabberd_gen_mam_archive).

-callback archive_size(Size :: integer(), Host :: ejabberd:server(),
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid())
-> integer().
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid())
-> integer().

-callback archive_message(_Result, ejabberd:server(),
MessID :: mod_mam:message_id(), ArchiveID :: mod_mam:archive_id(),
LocJID :: ejabberd:jid(), RemJID :: ejabberd:jid(),
SrcJID :: ejabberd:jid(), Dir :: atom(), Packet :: any()) -> ok | {error, timeout}.
MessID :: mod_mam:message_id(), ArchiveID :: mod_mam:archive_id(),
LocJID :: ejabberd:jid(), RemJID :: ejabberd:jid(),
SrcJID :: ejabberd:jid(), Dir :: atom(), Packet :: any()) ->
ok | {error, timeout}.

-callback lookup_messages(Result :: any(), Host :: ejabberd:server(),
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid(),
RSM :: jlib:rsm_in() | undefined, Borders :: mod_mam:borders() | undefined,
Start :: mod_mam:unix_timestamp() | undefined,
End :: mod_mam:unix_timestamp() | undefined, Now :: mod_mam:unix_timestamp(),
WithJID :: ejabberd:jid() | undefined, PageSize :: integer(),
LimitPassed :: boolean() | opt_count, MaxResultLimit :: integer(),
IsSimple :: boolean()) -> {ok, mod_mam:lookup_result()}
| {error, 'policy-violation'}.
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid(),
RSM :: jlib:rsm_in() | undefined,
Borders :: mod_mam:borders() | undefined,
Start :: mod_mam:unix_timestamp() | undefined,
End :: mod_mam:unix_timestamp() | undefined,
Now :: mod_mam:unix_timestamp(),
WithJID :: ejabberd:jid() | undefined,
SearchText :: binary() | undefined, PageSize :: integer(),
LimitPassed :: boolean() | opt_count, MaxResultLimit :: integer(),
IsSimple :: boolean()) -> {ok, mod_mam:lookup_result()}
| {error, 'policy-violation'}.

-callback remove_archive(Acc :: map(), Host :: ejabberd:server(),
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid()) -> map().

-callback purge_single_message(Result :: purge_single_message_result(), Host :: ejabberd:server(),
MessID :: mod_mam:message_id(), ArchiveID :: mod_mam:archive_id(),
ArchiveJID :: ejabberd:jid(), Now :: mod_mam:unix_timestamp())
-> purge_single_message_result().
MessID :: mod_mam:message_id(), ArchiveID :: mod_mam:archive_id(),
ArchiveJID :: ejabberd:jid(), Now :: mod_mam:unix_timestamp())
-> purge_single_message_result().

-callback purge_multiple_messages(Result :: any(), Host :: ejabberd:server(),
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid(),
Borders :: mod_mam:borders() | undefined,
Start :: mod_mam:unix_timestamp() | undefined,
End :: mod_mam:unix_timestamp() | undefined,
Now :: mod_mam:unix_timestamp(),
WithJID :: ejabberd:jid() | undefined) -> ok | {error, 'not-allowed'}.
ArchiveID :: mod_mam:archive_id(), ArchiveJID :: ejabberd:jid(),
Borders :: mod_mam:borders() | undefined,
Start :: mod_mam:unix_timestamp() | undefined,
End :: mod_mam:unix_timestamp() | undefined,
Now :: mod_mam:unix_timestamp(),
WithJID :: ejabberd:jid() | undefined) ->
ok | {error, 'not-allowed'}.

-type purge_single_message_result() :: ok | {error, 'not-allowed' | 'not-found' | term()}.

Expand Down
7 changes: 4 additions & 3 deletions apps/ejabberd/src/mod_commands.erl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ send_message(From, To, Body) ->
ejabberd_hooks:run(user_send_packet,
F#jid.lserver,
[F, T, Packet]),
% privacy check is missing, but is it needed?
%% privacy check is missing, but is it needed?
ejabberd_router:route(F, T, Packet),
ok.

Expand Down Expand Up @@ -242,15 +242,16 @@ lookup_recent_messages(ArcJID, WithJID, Before, Limit) ->
RSM = #rsm_in{direction = before, id = undefined}, % last msgs
Start = undefined,
End = Before * 1000000,
Now = mod_mam_utils:now_to_microseconds(os:timestamp()),
Now = p1_time_compat:os_system_time(micro_seconds),
WithJID = WithJID,
SearchText = undefined,
PageSize = Limit,
LimitPassed = false,
MaxResultLimit = 1,
IsSimple = true,
R = ejabberd_hooks:run_fold(mam_lookup_messages, Host, {ok, {0, 0, []}},
[Host, ArcID, ArcJID, RSM, Borders,
Start, End, Now, WithJID,
Start, End, Now, WithJID, SearchText,
PageSize, LimitPassed, MaxResultLimit, IsSimple]),
{ok, {_, _, L}} = R,
L.
Expand Down
Loading