Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: HanamiSearch v1.5 #213

Merged
merged 11 commits into from
Jan 19, 2025
2 changes: 1 addition & 1 deletion packages/backend/src/core/CoreModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { ProxyAccountService } from './ProxyAccountService.js';
import { UtilityService } from './UtilityService.js';
import { FileInfoService } from './FileInfoService.js';
import { SearchService } from './SearchService.js';
import { HanamiSearchService } from './HanamiSearchService.js';
import { HanamiSearchService } from './hanamisearch/HanamiSearchService.js';
import { ClipService } from './ClipService.js';
import { FeaturedService } from './FeaturedService.js';
import { FanoutTimelineService } from './FanoutTimelineService.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js';
import { bindThis } from '@/decorators.js';
import { DB_MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { RoleService } from '@/core/RoleService.js';
import { HanamiSearchService } from '@/core/HanamiSearchService.js';
import { HanamiSearchService } from '@/core/hanamisearch/HanamiSearchService.js';
import { FeaturedService } from '@/core/FeaturedService.js';
import { FanoutTimelineNamePrefix, FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { UtilityService } from '@/core/UtilityService.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/NoteDeleteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
import { HanamiSearchService } from '@/core/HanamiSearchService.js';
import { HanamiSearchService } from '@/core/hanamisearch/HanamiSearchService.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { isQuote, isRenote } from '@/misc/is-renote.js';
import { SearchService } from './SearchService.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export class HanamiSearchService {
private notesRepository: NotesRepository,

private cacheService: CacheService,
private queryService: QueryService,
private idService: IdService,
) {
this.hanamisearchIndexScope = config.hanamisearch?.scope || 'global';
Expand All @@ -100,6 +99,7 @@ export class HanamiSearchService {
'userHost',
'channelId',
'tags',
'fileIds',
],
typoTolerance: {
enabled: false,
Expand All @@ -116,6 +116,10 @@ export class HanamiSearchService {
if (note.text == null && note.cw == null) return;
if (!['home', 'public'].includes(note.visibility)) return;

// 配列が空の場合は null にする(検索時のパフォーマンスのためにインデックスしない)
const fileIds = (note.fileIds.length > 0) ? note.fileIds : null;
const tags = (note.tags.length > 0) ? note.tags : null;

const createdAt = this.idService.parse(note.id).date.getTime();
const noteData = {
id: note.id,
Expand All @@ -125,7 +129,8 @@ export class HanamiSearchService {
channelId: note.channelId,
cw: note.cw,
text: note.text,
tags: note.tags,
tags: tags,
fileIds: fileIds,
};

const shouldIndex = (scope: string | string[], userHost: string | null): boolean => {
Expand Down Expand Up @@ -165,6 +170,7 @@ export class HanamiSearchService {
channelId?: MiNote['channelId'] | null;
host?: string | null;
preferredMethod?: 'hanamisearchv1' | 'hanamisearchv2' | null;
onlyWithFiles?: boolean;
},
pagination: {
untilId?: MiNote['id'];
Expand All @@ -191,6 +197,7 @@ export class HanamiSearchService {
userId?: MiNote['userId'] | null;
channelId?: MiNote['channelId'] | null;
host?: string | null;
onlyWithFiles?: boolean;
},
pagination: {
untilId?: MiNote['id'];
Expand All @@ -208,6 +215,7 @@ export class HanamiSearchService {
if (opts.host) {
filter.qs.push(opts.host === '.' ? { op: 'is null', k: 'userHost' } : { op: '=', k: 'userHost', v: opts.host });
}
if (opts.onlyWithFiles) filter.qs.push({ op: 'is not null', k: 'fileIds' });

const res = await searchClient.search(q, {
sort: shouldTimeSeriesSort ? ['createdAt:desc'] : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { MiNote } from '@/models/Note.js';
import { EmailService } from '@/core/EmailService.js';
import { bindThis } from '@/decorators.js';
import { SearchService } from '@/core/SearchService.js';
import { HanamiSearchService } from '@/core/HanamiSearchService.js';
import { HanamiSearchService } from '@/core/hanamisearch/HanamiSearchService.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
import type { DbUserDeleteJobData } from '../types.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { HanamiSearchService } from '@/core/HanamiSearchService.js';
import { HanamiSearchService } from '@/core/hanamisearch/HanamiSearchService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { isMustRemove } from '@/misc/is-hidden-or-visibility-modified.js';

Expand Down Expand Up @@ -43,6 +43,7 @@ export const paramDef = {
},
userId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
onlyWithFiles: { type: 'boolean', default: false },
},
required: ['query'],
} as const;
Expand All @@ -61,6 +62,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
channelId: ps.channelId,
host: ps.host,
preferredMethod: 'hanamisearchv1',
onlyWithFiles: ps.onlyWithFiles,
}, {
untilId: ps.untilId,
sinceId: ps.sinceId,
Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23082,6 +23082,8 @@ export type operations = {
* @default null
*/
channelId?: string | null;
/** @default false */
onlyWithFiles?: boolean;
};
};
};
Expand Down
Loading