summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrivateGER <privateger@privateger.me>2025-02-19 16:26:02 +0100
committerPrivateGER <privateger@privateger.me>2025-02-19 16:32:11 +0100
commite6464906e6f96efcc93ef2d89c29065160a70243 (patch)
tree2768c43f080c04cc1355f02dd30d0ae7551ed091
parentadjust docs (diff)
downloadsharkey-e6464906e6f96efcc93ef2d89c29065160a70243.tar.gz
sharkey-e6464906e6f96efcc93ef2d89c29065160a70243.tar.bz2
sharkey-e6464906e6f96efcc93ef2d89c29065160a70243.zip
change to sqlTsvector
-rw-r--r--packages/backend/src/core/SearchService.ts61
1 files changed, 5 insertions, 56 deletions
diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts
index c99944fa51..2934d08c2d 100644
--- a/packages/backend/src/core/SearchService.ts
+++ b/packages/backend/src/core/SearchService.ts
@@ -240,7 +240,8 @@ export class SearchService {
): Promise<MiNote[]> {
switch (this.provider) {
case 'sqlLike':
- case 'sqlPgroonga': {
+ case 'sqlPgroonga':
+ case 'tsvector': {
// ほとんど内容に差がないのでsqlLikeとsqlPgroongaを同じ処理にしている.
// 今後の拡張で差が出る用であれば関数を分ける.
return this.searchNoteByLike(q, me, opts, pagination);
@@ -248,9 +249,6 @@ export class SearchService {
case 'meilisearch': {
return this.searchNoteByMeiliSearch(q, me, opts, pagination);
}
- case 'tsvector': {
- return this.searchNoteByTsvector(q, me, opts, pagination);
- }
default: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const typeCheck: never = this.provider;
@@ -260,57 +258,6 @@ export class SearchService {
}
@bindThis
- private async searchNoteByTsvector(q: string,
- me: MiUser | null,
- opts: SearchOpts,
- pagination: SearchPagination,
- ): Promise<MiNote[]> {
- const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);
-
- if (opts.userId) {
- query.andWhere('note.userId = :userId', { userId: opts.userId });
- } else if (opts.channelId) {
- query.andWhere('note.channelId = :channelId', { channelId: opts.channelId });
- }
-
- query
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
-
- query.andWhere('note.tsvector_embedding @@ websearch_to_tsquery(:q)', { q });
-
- if (opts.order === 'asc') {
- query
- .addSelect('ts_rank_cd(note.tsvector_embedding, websearch_to_tsquery(:q))', 'rank')
- .orderBy('rank', 'DESC');
- } else {
- query
- .orderBy('note.created_at', 'DESC');
- }
-
- if (opts.host) {
- if (opts.host === '.') {
- query.andWhere('note.userHost IS NULL');
- } else {
- query.andWhere('note.userHost = :host', { host: opts.host });
- }
- }
-
- if (opts.filetype) {
- query.andWhere('note."attachedFileTypes" && :types', { types: fileTypes[opts.filetype] });
- }
-
- this.queryService.generateVisibilityQuery(query, me);
- if (me) this.queryService.generateMutedUserQuery(query, me);
- if (me) this.queryService.generateBlockedUserQuery(query, me);
-
- return await query.limit(pagination.limit).getMany();
- }
-
- @bindThis
private async searchNoteByLike(
q: string,
me: MiUser | null,
@@ -333,7 +280,9 @@ export class SearchService {
.leftJoinAndSelect('renote.user', 'renoteUser');
if (this.config.fulltextSearch?.provider === 'sqlPgroonga') {
- query.andWhere('note.text &@~ :q', { q });
+ query.andWhere('note.text &@~ :q', {q});
+ } else if (this.config.fulltextSearch?.provider === "tsvector") {
+ query.andWhere('note.tsvector_embedding @@ websearch_to_tsquery(:q)', { q });
} else {
query.andWhere('note.text ILIKE :q', { q: `%${ sqlLikeEscape(q) }%` });
}