mirror of
https://github.com/zadam/trilium.git
synced 2025-12-05 15:04:24 +01:00
feat(fts): update imports from breaking up large fts_search file
This commit is contained in:
parent
9940ee3bee
commit
574a3441ee
@ -10,7 +10,7 @@ import cls from "../../services/cls.js";
|
||||
import attributeFormatter from "../../services/attribute_formatter.js";
|
||||
import ValidationError from "../../errors/validation_error.js";
|
||||
import type SearchResult from "../../services/search/search_result.js";
|
||||
import ftsSearchService from "../../services/search/fts_search.js";
|
||||
import { ftsSearchService } from "../../services/search/fts/index.js";
|
||||
import log from "../../services/log.js";
|
||||
import hoistedNoteService from "../../services/hoisted_note.js";
|
||||
import beccaService from "../../becca/becca_service.js";
|
||||
|
||||
@ -20,7 +20,7 @@ import {
|
||||
getRegex,
|
||||
FUZZY_SEARCH_CONFIG
|
||||
} from "../utils/text_utils.js";
|
||||
import ftsSearchService, { FTSError, FTSQueryError } from "../fts_search.js";
|
||||
import { ftsSearchService, FTSError, FTSQueryError } from "../fts/index.js";
|
||||
|
||||
const ALLOWED_OPERATORS = new Set(["=", "!=", "*=*", "*=", "=*", "%=", "~=", "~*"]);
|
||||
|
||||
|
||||
@ -77,12 +77,6 @@ export function sanitizeFTS5Token(token: string): string {
|
||||
return "__empty_token__";
|
||||
}
|
||||
|
||||
// Additional validation: ensure token doesn't contain SQL injection attempts
|
||||
if (sanitized.includes(';') || sanitized.includes('--')) {
|
||||
log.error(`Potential SQL injection attempt detected in token: "${token}"`);
|
||||
return "__invalid_token__";
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { ftsSearchService } from "./fts_search.js";
|
||||
import { ftsSearchService } from "./fts/index.js";
|
||||
import searchService from "./services/search.js";
|
||||
import BNote from "../../becca/entities/bnote.js";
|
||||
import BBranch from "../../becca/entities/bbranch.js";
|
||||
|
||||
@ -55,7 +55,7 @@ describe('FTS5 Search Service Improvements', () => {
|
||||
vi.doMock('../protected_session.js', () => ({ default: mockProtectedSession }));
|
||||
|
||||
// Import the service after mocking
|
||||
const module = await import('./fts_search.js');
|
||||
const module = await import('./fts/index.js');
|
||||
ftsSearchService = module.ftsSearchService;
|
||||
});
|
||||
|
||||
@ -151,15 +151,15 @@ describe('FTS5 Search Service Improvements', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should detect potential SQL injection attempts', () => {
|
||||
it('should allow tokens with semicolons and dashes (valid search content)', () => {
|
||||
mockSql.getValue.mockReturnValue(1);
|
||||
|
||||
|
||||
// Users may search for SQL code snippets or other content containing these characters
|
||||
const query = ftsSearchService.convertToFTS5Query(['test; DROP TABLE'], '=');
|
||||
|
||||
expect(query).toContain('__invalid_token__');
|
||||
expect(mockLog.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Potential SQL injection attempt detected')
|
||||
);
|
||||
|
||||
// Should preserve the content, not reject it
|
||||
expect(query).toBe('"test; DROP TABLE"');
|
||||
expect(query).not.toContain('__invalid_token__');
|
||||
});
|
||||
|
||||
it('should properly sanitize valid tokens', () => {
|
||||
@ -268,7 +268,7 @@ describe('searchWithLike - Substring Search with LIKE Queries', () => {
|
||||
vi.doMock('../protected_session.js', () => ({ default: mockProtectedSession }));
|
||||
|
||||
// Import the service after mocking
|
||||
const module = await import('./fts_search.js');
|
||||
const module = await import('./fts/index.js');
|
||||
ftsSearchService = module.ftsSearchService;
|
||||
});
|
||||
|
||||
@ -1320,7 +1320,7 @@ describe('Exact Match with Word Boundaries (= operator)', () => {
|
||||
vi.doMock('../protected_session.js', () => ({ default: mockProtectedSession }));
|
||||
|
||||
// Import the service after mocking
|
||||
const module = await import('./fts_search.js');
|
||||
const module = await import('./fts/index.js');
|
||||
ftsSearchService = module.ftsSearchService;
|
||||
});
|
||||
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* FTS5 Search Service
|
||||
*
|
||||
* This module re-exports from the fts/ folder for backward compatibility.
|
||||
* New code should import directly from './fts/index.js' or './fts/<module>.js'.
|
||||
*/
|
||||
|
||||
export {
|
||||
// Error classes
|
||||
FTSError,
|
||||
FTSQueryError,
|
||||
|
||||
// Types and configuration
|
||||
FTS_CONFIG,
|
||||
type FTSSearchResult,
|
||||
type FTSSearchOptions,
|
||||
type FTSErrorInfo,
|
||||
type FTSIndexStats,
|
||||
|
||||
// Query building utilities
|
||||
convertToFTS5Query,
|
||||
sanitizeFTS5Token,
|
||||
escapeLikeWildcards,
|
||||
containsExactPhrase,
|
||||
generateSnippet,
|
||||
|
||||
// Index management
|
||||
assertFTS5Available,
|
||||
checkFTS5Availability,
|
||||
updateNoteIndex,
|
||||
removeNoteFromIndex,
|
||||
syncMissingNotes,
|
||||
rebuildIndex,
|
||||
getIndexStats,
|
||||
filterNonProtectedNoteIds,
|
||||
|
||||
// Search operations
|
||||
searchWithLike,
|
||||
searchSync,
|
||||
searchAttributesSync,
|
||||
searchProtectedNotesSync,
|
||||
|
||||
// Legacy class-based API
|
||||
ftsSearchService
|
||||
} from "./fts/index.js";
|
||||
|
||||
// Default export for backward compatibility
|
||||
export { default } from "./fts/index.js";
|
||||
Loading…
x
Reference in New Issue
Block a user