Revert "update SearchService"

This reverts commit e692e7ac6f.
This commit is contained in:
fly_mc 2024-11-17 19:04:47 +08:00
parent 1482acd354
commit 6c9dd99083

View file

@ -4,7 +4,7 @@
*/
import { Inject, Injectable } from '@nestjs/common';
import { In, SelectQueryBuilder } from 'typeorm';
import { In } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { bindThis } from '@/decorators.js';
@ -206,7 +206,6 @@ export class SearchService {
});
return notes.sort((a, b) => a.id > b.id ? -1 : 1);
} else {
const searchByPgroonga = async (makeQuery: (query: SelectQueryBuilder<MiNote>) => void) => {
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);
if (opts.userId) {
@ -222,7 +221,6 @@ export class SearchService {
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser');
makeQuery(query);
if (opts.host) {
if (opts.host === '.') {
@ -237,29 +235,6 @@ export class SearchService {
if (me) this.queryService.generateBlockedUserQuery(query, me);
return await query.limit(pagination.limit).getMany();
};
const searchWord = sqlLikeEscape(q);
const notes = [
...new Map(
(
await Promise.all([
searchByPgroonga((query) => {
query.andWhere('note.text &@~ :q', { q: searchWord });
}),
searchByPgroonga((query) => {
query.andWhere('note.cw &@~ :q', { q: searchWord });
}),
])
)
.flatMap((e) => e)
.map((note) => [note.id, note]),
).values(),
]
.sort((lhs, rhs) => lhs.id < rhs.id ? 1 : -1)
.slice(0, pagination.limit);
return notes;
}
}
}