Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32400001
D7077.1765340217.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7077.1765340217.diff
View Options
diff --git a/keyserver/src/creators/message-creator.js b/keyserver/src/creators/message-creator.js
--- a/keyserver/src/creators/message-creator.js
+++ b/keyserver/src/creators/message-creator.js
@@ -32,6 +32,7 @@
appendSQLArray,
mergeOrConditions,
} from '../database/database.js';
+import { processMessagesForSearch } from '../database/search-utils.js';
import {
fetchMessageInfoForLocalID,
fetchMessageInfoByID,
@@ -288,6 +289,7 @@
// (1) Sending push notifs
// (2) Setting threads to unread and generating corresponding UpdateInfos
// (3) Publishing to Redis so that active sockets pass on new messages
+// (4) Processing messages for search
async function postMessageSend(
viewer: Viewer,
threadsToMessageIndices: Map<string, number[]>,
@@ -296,6 +298,8 @@
messageDatas: MessageData[],
updatesForCurrentSession: UpdatesForCurrentSession,
) {
+ processMessagesForSearch(messageInfos);
+
let joinIndex = 0;
let subthreadSelects = '';
const subthreadJoins = [];
diff --git a/keyserver/src/database/search-utils.js b/keyserver/src/database/search-utils.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/database/search-utils.js
@@ -0,0 +1,48 @@
+// @flow
+
+import natural from 'natural';
+
+import type { RawMessageInfo } from 'lib/types/message-types';
+import { messageTypes } from 'lib/types/message-types.js';
+
+import { dbQuery, SQL } from '../database/database.js';
+
+async function processMessagesForSearch(
+ messages: $ReadOnlyArray<RawMessageInfo>,
+): Promise<void> {
+ const processedMessages = [];
+
+ for (const msg of messages) {
+ if (
+ msg.type !== messageTypes.TEXT &&
+ msg.type !== messageTypes.EDIT_MESSAGE
+ ) {
+ continue;
+ }
+
+ const processed_msg = natural.PorterStemmer.tokenizeAndStem(
+ msg.text,
+ false,
+ ).join(' ');
+
+ if (msg.type === messageTypes.TEXT) {
+ processedMessages.push([msg.id, msg.id, processed_msg]);
+ } else {
+ processedMessages.push([msg.targetMessageID, msg.id, processed_msg]);
+ }
+ }
+
+ if (processedMessages.length === 0) {
+ return;
+ }
+
+ await dbQuery(SQL`
+ INSERT INTO search (original_message_id, message_id, processed_content)
+ VALUES ${processedMessages}
+ ON DUPLICATE KEY UPDATE
+ message_id = VALUE(message_id),
+ processed_content = VALUE(processed_content);
+ `);
+}
+
+export { processMessagesForSearch };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 4:16 AM (10 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5860799
Default Alt Text
D7077.1765340217.diff (2 KB)
Attached To
Mode
D7077: [keyserver] Process new messages for search
Attached
Detach File
Event Timeline
Log In to Comment