一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
50 行
1.6 KiB
TypeScript
50 行
1.6 KiB
TypeScript
import Note from '../../models/Note';
|
|
import { setUpSemanticSearch, tearDownSemanticSearch, updateSearchIndex } from '../../testing/ai/semanticSearch';
|
|
import { setupDatabaseAndSynchronizer, switchClient } from '../../testing/test-utils';
|
|
import SearchEngine, { SearchType } from './SearchEngine';
|
|
|
|
describe('SearchEngine.semantic', () => {
|
|
let engine: SearchEngine = null;
|
|
|
|
beforeEach(async () => {
|
|
await setupDatabaseAndSynchronizer(1);
|
|
await switchClient(1);
|
|
|
|
await setUpSemanticSearch();
|
|
engine = SearchEngine.instance();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await tearDownSemanticSearch();
|
|
});
|
|
|
|
it('should include semantic results in general search output', async () => {
|
|
await Note.save({ title: 'test', body: 'letter letter letter' });
|
|
|
|
await updateSearchIndex();
|
|
|
|
const rows = await engine.search('letters letter letter');
|
|
expect(rows).toHaveLength(1);
|
|
expect(rows[0]).toMatchObject({ searchType: [SearchType.Semantic] });
|
|
});
|
|
|
|
it('should not use semantic search when the user has specified a field to search in', async () => {
|
|
await Note.save({ title: 'test', body: 'letter' });
|
|
|
|
await updateSearchIndex();
|
|
|
|
const rows = await engine.search('body:letters letter letter');
|
|
expect(rows).toHaveLength(0);
|
|
});
|
|
|
|
it('should not use semantic search when searching for an item ID-like pattern', async () => {
|
|
const testUuid = '5d17d3649e0449209db61fdbf6b27d14';
|
|
await Note.save({ title: 'test', body: testUuid });
|
|
|
|
await updateSearchIndex();
|
|
|
|
expect(await engine.search(testUuid)).toHaveLength(1);
|
|
expect(await engine.search(testUuid.replace(/.$/, 'a'))).toHaveLength(0);
|
|
});
|
|
});
|