Skip to content

Commit

Permalink
chore & fix: v2で対応予定の機能がv1に当てがわれていた問題を修正 (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarikanaru authored Dec 31, 2024
1 parent def9264 commit e1eeddb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/backend/src/core/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class SearchService {
userId?: MiNote['userId'] | null;
channelId?: MiNote['channelId'] | null;
host?: string | null;
preferredMethod?: 'meilisearch' | 'hanamisearch' | null;
preferredMethod?: 'meilisearch' | 'hanamisearchv1' | 'hanamisearchv2' | null;
},
pagination: {
untilId?: MiNote['id'];
Expand All @@ -200,10 +200,10 @@ export class SearchService {
): Promise<MiNote[]> {
const preferredMethod = opts.preferredMethod ?? 'meilisearch';

if ((preferredMethod === 'meilisearch' && this.meilisearch) || (preferredMethod === 'hanamisearch' && this.hanamisearch)) {
if ((preferredMethod === 'meilisearch' && this.meilisearch) || (preferredMethod === 'hanamisearchv1' && this.hanamisearch)) {
const searchClient = preferredMethod === 'meilisearch' ? this.meilisearchNoteIndex! : this.hanamisearchNoteIndex!;
const shouldSort = preferredMethod === 'meilisearch';
return this.searchWithExternalEngine(searchClient, q, me, opts, pagination, shouldSort);
const shouldTimeSeriesSort = true;
return this.searchWithExternalEngine(searchClient, q, me, opts, pagination, shouldTimeSeriesSort);
}

if (!this.meilisearch && !this.hanamisearch && preferredMethod === 'meilisearch') {
Expand All @@ -227,7 +227,7 @@ export class SearchService {
sinceId?: MiNote['id'];
limit?: number;
},
shouldSort: boolean,
shouldTimeSeriesSort: boolean,
): Promise<MiNote[]> {
const filter: Q = { op: 'and', qs: [] };

Expand All @@ -240,7 +240,7 @@ export class SearchService {
}

const res = await searchClient.search(q, {
sort: shouldSort ? ['createdAt:desc'] : undefined,
sort: shouldTimeSeriesSort ? ['createdAt:desc'] : undefined,
matchingStrategy: 'all',
attributesToRetrieve: ['id', 'createdAt'],
filter: compileQuery(filter),
Expand All @@ -265,7 +265,7 @@ export class SearchService {
});

// ソートは MeiliSearch の場合のみ適用
return shouldSort ? notes.sort((a, b) => (a.id > b.id ? -1 : 1)) : notes;
return shouldTimeSeriesSort ? notes.sort((a, b) => (a.id > b.id ? -1 : 1)) : notes;
}

private async searchWithInternalDB(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
userId: ps.userId,
channelId: ps.channelId,
host: ps.host,
preferredMethod: 'hanamisearch',
preferredMethod: 'hanamisearchv1',
}, {
untilId: ps.untilId,
sinceId: ps.sinceId,
Expand Down

0 comments on commit e1eeddb

Please sign in to comment.