mirror of
https://github.com/paricafe/misskey.git
synced 2025-02-17 14:47:29 -06:00
parent
1471039199
commit
cb9385e229
1 changed files with 51 additions and 26 deletions
|
@ -4,7 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { In } from 'typeorm';
|
import { In, SelectQueryBuilder } from 'typeorm';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { Config } from '@/config.js';
|
import type { Config } from '@/config.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
@ -206,35 +206,60 @@ export class SearchService {
|
||||||
});
|
});
|
||||||
return notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
return notes.sort((a, b) => a.id > b.id ? -1 : 1);
|
||||||
} else {
|
} else {
|
||||||
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);
|
const searchByPgroonga = async (makeQuery: (query: SelectQueryBuilder<MiNote>) => void) => {
|
||||||
|
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), pagination.sinceId, pagination.untilId);
|
||||||
|
|
||||||
if (opts.userId) {
|
if (opts.userId) {
|
||||||
query.andWhere('note.userId = :userId', { userId: opts.userId });
|
query.andWhere('note.userId = :userId', { userId: opts.userId });
|
||||||
} else if (opts.channelId) {
|
} else if (opts.channelId) {
|
||||||
query.andWhere('note.channelId = :channelId', { channelId: opts.channelId });
|
query.andWhere('note.channelId = :channelId', { channelId: opts.channelId });
|
||||||
}
|
|
||||||
|
|
||||||
query
|
|
||||||
.andWhere('note.text &@~ :q', { q: sqlLikeEscape(q) })
|
|
||||||
.innerJoinAndSelect('note.user', 'user')
|
|
||||||
.leftJoinAndSelect('note.reply', 'reply')
|
|
||||||
.leftJoinAndSelect('note.renote', 'renote')
|
|
||||||
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
||||||
.leftJoinAndSelect('renote.user', 'renoteUser');
|
|
||||||
|
|
||||||
if (opts.host) {
|
|
||||||
if (opts.host === '.') {
|
|
||||||
query.andWhere('user.host IS NULL');
|
|
||||||
} else {
|
|
||||||
query.andWhere('user.host = :host', { host: opts.host });
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
query
|
||||||
if (me) this.queryService.generateMutedUserQuery(query, me);
|
.andWhere('note.text &@~ :q', { q: sqlLikeEscape(q) })
|
||||||
if (me) this.queryService.generateBlockedUserQuery(query, me);
|
.innerJoinAndSelect('note.user', 'user')
|
||||||
|
.leftJoinAndSelect('note.reply', 'reply')
|
||||||
|
.leftJoinAndSelect('note.renote', 'renote')
|
||||||
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
||||||
|
.leftJoinAndSelect('renote.user', 'renoteUser');
|
||||||
|
makeQuery(query);
|
||||||
|
|
||||||
return await query.limit(pagination.limit).getMany();
|
if (opts.host) {
|
||||||
|
if (opts.host === '.') {
|
||||||
|
query.andWhere('user.host IS NULL');
|
||||||
|
} else {
|
||||||
|
query.andWhere('user.host = :host', { host: opts.host });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue