Refactor document search

This commit is contained in:
Tom Moor
2022-10-30 12:41:52 -04:00
parent 86aa531fad
commit 1e62d25861
6 changed files with 652 additions and 602 deletions

View File

@@ -30,6 +30,7 @@ import {
View,
} from "@server/models";
import DocumentHelper from "@server/models/helpers/DocumentHelper";
import SearchHelper from "@server/models/helpers/SearchHelper";
import { authorize, cannot } from "@server/policies";
import {
presentCollection,
@@ -701,7 +702,7 @@ router.post(
const team = await share.$get("team");
invariant(team, "Share must belong to a team");
response = await Document.searchForTeam(team, query, {
response = await SearchHelper.searchForTeam(team, query, {
includeArchived,
includeDrafts,
collectionId: document.collectionId,
@@ -742,7 +743,7 @@ router.post(
);
}
response = await Document.searchForUser(user, query, {
response = await SearchHelper.searchForUser(user, query, {
includeArchived,
includeDrafts,
collaboratorIds,

View File

@@ -14,6 +14,7 @@ import {
Integration,
IntegrationAuthentication,
} from "@server/models";
import SearchHelper from "@server/models/helpers/SearchHelper";
import { presentSlackAttachment } from "@server/presenters";
import * as Slack from "@server/utils/slack";
import { assertPresent } from "@server/validation";
@@ -281,8 +282,8 @@ router.post("hooks.slack", async (ctx) => {
// to load more documents based on the collections they have access to. Otherwise
// just a generic search against team-visible documents is allowed.
const { results, totalCount } = user
? await Document.searchForUser(user, text, options)
: await Document.searchForTeam(team, text, options);
? await SearchHelper.searchForUser(user, text, options)
: await SearchHelper.searchForTeam(team, text, options);
SearchQuery.create({
userId: user ? user.id : null,
teamId: team.id,