Skip to content

TagSpaces is an offline, open source, document manager with tagging support

adding basic support for full text search

Ilian Sapundshievfc74a7898ac1
diff --git a/app/reducers/app.js b/app/reducers/app.js
index 61687c21e..72682ec96 100644
--- a/app/reducers/app.js
+++ b/app/reducers/app.js
@@ -904,7 +904,7 @@ export const actions = {
if (location.persistIndex) {
dispatch(LocationIndexActions.loadDirectoryIndex(location.paths[0]));
} else {
- dispatch(LocationIndexActions.createDirectoryIndex(location.paths[0]));
+ dispatch(LocationIndexActions.createDirectoryIndex(location.paths[0], true));
}
}
if (Pro && Pro.Watcher && location.watchForChanges) {
diff --git a/app/reducers/location-index.js b/app/reducers/location-index.js
index 632e02583..083796571 100644
--- a/app/reducers/location-index.js
+++ b/app/reducers/location-index.js
@@ -212,14 +212,14 @@ export default (state: Object = initialState, action: Object) => {
export const actions = {
startDirectoryIndexing: () => ({ type: types.INDEX_DIRECTORY_START }),
cancelDirectoryIndexing: () => ({ type: types.INDEX_DIRECTORY_CANCEL }),
- createDirectoryIndex: (directoryPath: string) => (
+ createDirectoryIndex: (directoryPath: string, extractText: boolean) => (
dispatch: (actions: Object) => void,
getState: () => Object
) => {
const state = getState();
const currentLocation: Location = getLocation(state, state.app.currentLocationId);
dispatch(actions.startDirectoryIndexing());
- createDirectoryIndex(directoryPath)
+ createDirectoryIndex(directoryPath, extractText)
.then(directoryIndex => {
dispatch(actions.indexDirectorySuccess(directoryIndex));
if (Pro && currentLocation.persistIndex) {
diff --git a/app/services/platform-io.js b/app/services/platform-io.js
index c95f160d7..e97261aa8 100644
--- a/app/services/platform-io.js
+++ b/app/services/platform-io.js
@@ -114,8 +114,8 @@ export default class PlatformIO {
static createDirectoryTree = (directoryPath: string): Object =>
nativeAPI.createDirectoryTree(directoryPath);
- static createDirectoryIndexInWorker = (directoryPath: string): Promise<any> =>
- nativeAPI.createDirectoryIndexInWorker(directoryPath);
+ static createDirectoryIndexInWorker = (directoryPath: string, extractText: boolean): Promise<any> =>
+ nativeAPI.createDirectoryIndexInWorker(directoryPath, extractText);
static createThumbnailsInWorker = (
tmbGenerationList: Array<string>
@@ -123,12 +123,13 @@ export default class PlatformIO {
static listDirectoryPromise = (
path: string,
- lite: boolean = true
+ lite: boolean = true,
+ extractText: boolean = true
): Promise<Array<any>> => {
if (objectStoreAPI) {
return objectStoreAPI.listDirectoryPromise(path, lite);
}
- return nativeAPI.listDirectoryPromise(path, lite);
+ return nativeAPI.listDirectoryPromise(path, lite, extractText);
};
static getPropertiesPromise = (path: string): Promise<any> => {
diff --git a/app/services/search.js b/app/services/search.js
index 6947df082..ee6039917 100644
--- a/app/services/search.js
+++ b/app/services/search.js
@@ -105,6 +105,9 @@ const fuseOptions = {
}, {
name: 'description',
weight: 0.4
+ }, {
+ name: 'textContent',
+ weight: 0.4
}, {
name: 'tags',
weight: 0.3
diff --git a/app/services/utils-io.js b/app/services/utils-io.js
index a2a056ab5..2b9a37b78 100644
--- a/app/services/utils-io.js
+++ b/app/services/utils-io.js
@@ -39,6 +39,7 @@ export type FileSystemEntry = {
isFile: boolean,
extension: string,
thumbPath?: string,
+ textContent?: string,
description: string,
tags: Array<Tag>,
size: number,
@@ -76,6 +77,7 @@ export function enhanceEntry(entry: any): FileSystemEntry {
extension: entry.isFile ? extractFileExtension(entry.name) : '',
thumbPath: entry.thumbPath,
description: sidecarDescription,
+ textContent: entry.textContent,
tags: [...sidecarTags, ...fileNameTags],
size: entry.size,
lmdt: entry.lmdt,
@@ -85,10 +87,10 @@ export function enhanceEntry(entry: any): FileSystemEntry {
return enhancedEntry;
}
-export function createDirectoryIndex(directoryPath: string): Promise<Array<Object>> {
+export function createDirectoryIndex(directoryPath: string, extractText: boolean = false): Promise<Array<Object>> {
const dirPath = cleanTrailingDirSeparator(directoryPath);
if (PlatformIO.isWorkerAvailable() && !PlatformIO.haveObjectStoreSupport()) { // Start indexing in worker if not in the object store mode
- return PlatformIO.createDirectoryIndexInWorker(dirPath);
+ return PlatformIO.createDirectoryIndexInWorker(dirPath, extractText);
}
return new Promise((resolve, reject) => {
@@ -96,7 +98,7 @@ export function createDirectoryIndex(directoryPath: string): Promise<Array<Objec
const directoryIndex = [];
let counter = 0;
console.time('createDirectoryIndex');
- walkDirectory(dirPath, { recursive: true, skipMetaFolder: true }, (fileEntry) => {
+ walkDirectory(dirPath, { recursive: true, skipMetaFolder: true, extractText }, (fileEntry) => {
counter += 1;
if (counter > AppConfig.indexerLimit) {
console.warn('Walk canceled by ' + AppConfig.indexerLimit);
@@ -126,11 +128,18 @@ export function createDirectoryIndex(directoryPath: string): Promise<Array<Objec
export function walkDirectory(
path: string,
- options: Object = { recursive: false, skipMetaFolder: true, loadMetaDate: true },
+ options: Object = {},
fileCallback: any,
dirCallback: any
) {
- return PlatformIO.listDirectoryPromise(path, false).then((entries) => {
+ const mergedOptions = {
+ recursive: false,
+ skipMetaFolder: true,
+ loadMetaDate: true,
+ extractText: false,
+ ...options
+ };
+ return PlatformIO.listDirectoryPromise(path, false, mergedOptions.extractText).then((entries) => {
if (window.walkCanceled) {
return false;
}
@@ -150,11 +159,11 @@ export function walkDirectory(
dirCallback(entry);
}
- if (options.recursive) {
- if (options.skipMetaFolder && entry.name === AppConfig.metaFolder) {
+ if (mergedOptions.recursive) {
+ if (mergedOptions.skipMetaFolder && entry.name === AppConfig.metaFolder) {
return entry;
}
- return walkDirectory(entry.path, options, fileCallback, dirCallback);
+ return walkDirectory(entry.path, mergedOptions, fileCallback, dirCallback);
}
return entry;
}));
diff --git a/app/splash-worker.js b/app/splash-worker.js
index 329d375f4..65b5392f7 100644
--- a/app/splash-worker.js
+++ b/app/splash-worker.js
@@ -27,14 +27,14 @@ let isGeneratingThumbs = false;
function init() {
console.log('Init worker');
ipcRenderer.on('worker', (event, arg) => {
- // console.log('worker recieved: ' + arg);
+ // console.log('worker recieved: ' + JSON.stringify(arg));
switch (arg.action) {
case 'createDirectoryIndex': {
console.log('createDirectoryIndex started in worker window');
console.time('createDirectoryIndex');
const directoryIndex = [];
let counter = 0;
- walkDirectory(arg.path, { recursive: true, skipMetaFolder: true }, (fileEntry) => {
+ walkDirectory(arg.path, { recursive: true, skipMetaFolder: true, extractText: arg.extractText }, (fileEntry) => {
counter += 1;
if (counter > AppConfig.indexerLimit) {
console.warn('Walk canceled by ' + AppConfig.indexerLimit);