1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Desktop: Resolves #12224: Add an option to enable or disable search in OCR text (#12578)

This commit is contained in:
pedr
2025-08-06 06:37:20 -03:00
committed by GitHub
parent b6d32831c6
commit 3f75d770f7
3 changed files with 42 additions and 2 deletions

View File

@@ -594,6 +594,16 @@ const builtInMetadata = (Setting: typeof SettingType) => {
label: () => _('OCR: Clear cache and re-download language data files'), label: () => _('OCR: Clear cache and re-download language data files'),
}, },
'ocr.searchInExtractedContent': {
value: true,
type: SettingItemType.Bool,
advanced: true,
public: true,
appTypes: [AppType.Desktop],
storage: SettingStorage.Database,
label: () => _('OCR: Search in extracted content'),
},
theme: { theme: {
value: Setting.THEME_LIGHT, value: Setting.THEME_LIGHT,
type: SettingItemType.Int, type: SettingItemType.Int,

View File

@@ -1,8 +1,10 @@
import { setupDatabaseAndSynchronizer, db, sleep, switchClient, msleep } from '../../testing/test-utils'; import { setupDatabaseAndSynchronizer, db, sleep, switchClient, msleep, createNoteAndResource } from '../../testing/test-utils';
import SearchEngine from './SearchEngine'; import SearchEngine from './SearchEngine';
import Note from '../../models/Note'; import Note from '../../models/Note';
import ItemChange from '../../models/ItemChange'; import ItemChange from '../../models/ItemChange';
import Setting from '../../models/Setting'; import Setting from '../../models/Setting';
import Resource from '../../models/Resource';
import { ResourceOcrStatus } from '../database/types';
let engine: SearchEngine = null; let engine: SearchEngine = null;
@@ -583,4 +585,32 @@ describe('services/SearchEngine', () => {
// expect(await engine.search(f1.id)).toEqual([]); // expect(await engine.search(f1.id)).toEqual([]);
// })); // }));
it.each(
[
['find', 'enabled', true, 1],
['not find', 'disabled', false, 0],
],
)('should %s resources if searching in OCR content is %s',
async (_testName: string, _testName2: string, isSearchEnabled: boolean, resourcesFound: number) => {
const { resource } = await createNoteAndResource();
await Resource.save({
id: resource.id,
ocr_status: ResourceOcrStatus.Done,
ocr_text: 'héllô, hôw äre yoù ?',
});
await engine.syncTables();
const normalized = await db().selectAll('select * from items_fts');
expect(normalized[0].body).toBe('hello, how are you ?');
Setting.setValue('ocr.searchInExtractedContent', isSearchEnabled);
const rows = await engine.search('hello', {
searchType: SearchEngine.SEARCH_TYPE_FTS,
includeOrphanedResources: true,
});
expect(rows.length).toBe(resourcesFound);
});
}); });

View File

@@ -815,7 +815,7 @@ export default class SearchEngine {
}; };
}); });
if (!queryHasFilters) { if (!queryHasFilters && Setting.value('ocr.searchInExtractedContent')) {
const toSearch = parsedQuery.allTerms.map(t => t.value).join(' '); const toSearch = parsedQuery.allTerms.map(t => t.value).join(' ');
let itemRows: ProcessResultsRow[] = []; let itemRows: ProcessResultsRow[] = [];