TagSpaces is an offline, open source, document manager with tagging support
added experimental full text search support for the desktop app
Ilian Sapundshievbac4f632ca89
diff --git a/app/components/dialogs/CreateLocationDialog.js b/app/components/dialogs/CreateLocationDialog.jsindex 92c4d5f91..8ef3dc827 100644--- a/app/components/dialogs/CreateLocationDialog.js+++ b/app/components/dialogs/CreateLocationDialog.js@@ -79,6 +79,7 @@ type State = {isReadOnly?: boolean,watchForChanges?: boolean,persistIndex?: boolean,+ fullTextIndex?: boolean,type: string};@@ -95,28 +96,10 @@ class CreateLocationDialog extends React.Component<Props, State> {isReadOnly: false,watchForChanges: Pro,persistIndex: false,+ fullTextIndex: false,type: locationType.TYPE_LOCAL};- /* componentWillReceiveProps = (nextProps: any) => {- if (nextProps.open === true) {- const dir = nextProps.selectedDirectoryPath;- this.setState({- name: dir ? extractDirectoryName(dir) : '',- path: dir || '',- perspective: '',- isDefault: false,- isReadOnly: false,- watchForChanges: !!Pro,- persistIndex: false- });- }- }; */-- /* componentWillUnmount = () => {- console.log('CreateLocationDialog componentWillUnmount');- }; */-handleInputChange = (event: Object) => {const target = event.target;const value = target.type === 'checkbox' ? target.checked : target.value;@@ -138,13 +121,6 @@ class CreateLocationDialog extends React.Component<Props, State> {});};- /* handleFieldValidation(field) {- if (!this.state[field] || this.state[field].length === 0) {- const errorName = 'error' + field;- this.setState({ [errorName]: true, disableConfirmButton: true });- }- } */-handleValidation(field) {// const pathRegex = this.state.path.match('^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9]+)$');// const nameRegex = this.state.name.match('^[A-Z][-a-zA-Z]+$');@@ -189,22 +165,6 @@ class CreateLocationDialog extends React.Component<Props, State> {}));}- /* if (!this.state.storePath || this.state.storePath.length === 0) {- cloudErrorTextPath = true;- disableConfirmButton = true;- } else if (field === 'storePath'- && !this.state.cloudErrorTextName- // && !this.state.cloudErrorTextPath- && !this.state.cloudErrorAccessKey- && !this.state.cloudErrorSecretAccessKey- && !this.state.cloudErrorBucketName- && !this.state.cloudErrorRegion- && this.state.disableConfirmButton) { // initial skip validation for other fields- return new Promise(((resolve) => {- resolve(true);- }));- } */-if (!this.state.accessKeyId || this.state.accessKeyId.length === 0) {cloudErrorAccessKey = true;disableConfirmButton = true;@@ -285,6 +245,7 @@ class CreateLocationDialog extends React.Component<Props, State> {isDefault: this.state.isDefault,isReadOnly: this.state.isReadOnly,persistIndex: this.state.persistIndex,+ fullTextIndex: this.state.fullTextIndex,watchForChanges: this.state.watchForChanges});} else if (this.state.type === locationType.TYPE_CLOUD) {@@ -301,6 +262,7 @@ class CreateLocationDialog extends React.Component<Props, State> {isDefault: this.state.isDefault,isReadOnly: this.state.isReadOnly,persistIndex: this.state.persistIndex,+ fullTextIndex: this.state.fullTextIndex,watchForChanges: false});}@@ -378,6 +340,18 @@ class CreateLocationDialog extends React.Component<Props, State> {}label={i18n.t('core:readonlyModeSwitch') + (Pro ? '' : ' - ' + i18n.t('core:proFeature'))}/> */}+ <FormControlLabel+ control={+ <Switch+ disabled={!Pro}+ data-tid="changeFullTextIndex"+ name="fullTextIndex"+ checked={this.state.fullTextIndex}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:createFullTextIndex') + (Pro ? '' : ' - ' + i18n.t('core:proFeature'))}+ /><FormControlLabelcontrol={<Switchdiff --git a/app/components/dialogs/EditLocationDialog.js b/app/components/dialogs/EditLocationDialog.jsindex d347e815d..11f9108c0 100644--- a/app/components/dialogs/EditLocationDialog.js+++ b/app/components/dialogs/EditLocationDialog.js@@ -63,6 +63,7 @@ type State = {isDefault?: boolean,isReadOnly?: boolean,watchForChanges?: boolean,+ fullTextIndex?: boolean,persistIndex?: boolean};@@ -80,6 +81,7 @@ class EditLocationDialog extends React.Component<Props, State> {isReadOnly: false,watchForChanges: false,persistIndex: false,+ fullTextIndex: false,type: locationType.TYPE_LOCAL};@@ -106,6 +108,7 @@ class EditLocationDialog extends React.Component<Props, State> {isReadOnly: nextProps.location.isReadOnly,watchForChanges: nextProps.location.watchForChanges,persistIndex: nextProps.location.persistIndex,+ fullTextIndex: nextProps.location.fullTextIndex,type: nextProps.location.type || locationType.TYPE_LOCAL,accessKeyId: nextProps.location.accessKeyId,secretAccessKey: nextProps.location.secretAccessKey,@@ -233,6 +236,7 @@ class EditLocationDialog extends React.Component<Props, State> {isDefault: this.state.isDefault,isReadOnly: this.state.isReadOnly,persistIndex: this.state.persistIndex,+ fullTextIndex: this.state.fullTextIndex,watchForChanges: this.state.watchForChanges});} else if (this.state.type === locationType.TYPE_CLOUD) {@@ -249,6 +253,7 @@ class EditLocationDialog extends React.Component<Props, State> {isDefault: this.state.isDefault,isReadOnly: this.state.isReadOnly,persistIndex: this.state.persistIndex,+ fullTextIndex: this.state.fullTextIndex,watchForChanges: false});}@@ -331,6 +336,18 @@ class EditLocationDialog extends React.Component<Props, State> {}label={i18n.t('core:readonlyModeSwitch') + (Pro ? '' : ' - ' + i18n.t('core:proFeature'))}/> */}+ <FormControlLabel+ control={+ <Switch+ disabled={!Pro}+ data-tid="changeFullTextIndex"+ name="fullTextIndex"+ checked={this.state.fullTextIndex}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:createFullTextIndex') + (Pro ? '' : ' - ' + i18n.t('core:proFeature'))}+ /><FormControlLabelcontrol={<Switchdiff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 781b64a41..030038241 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -330,6 +330,7 @@"indexLocation": "Refresh Location Index","readonlyModeSwitch": "Open this location in read-only mode","persistIndexSwitch": "Switch to manual index creation with persisted search index",+ "createFullTextIndex": "Enable full text search for TXT, MD and HTML files (BETA)","watchForChangesInLocation": "Watch for external changes in this location","proFeature": "feature available in the PRO version","collectedTags": "Collected Tags",diff --git a/app/reducers/app.js b/app/reducers/app.jsindex 72682ec96..dcbf34327 100644--- a/app/reducers/app.js+++ b/app/reducers/app.js@@ -887,7 +887,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], location.fullTextIndex));}}return true;@@ -904,7 +904,7 @@ export const actions = {if (location.persistIndex) {dispatch(LocationIndexActions.loadDirectoryIndex(location.paths[0]));} else {- dispatch(LocationIndexActions.createDirectoryIndex(location.paths[0], true));+ dispatch(LocationIndexActions.createDirectoryIndex(location.paths[0], location.fullTextIndex));}}if (Pro && Pro.Watcher && location.watchForChanges) {diff --git a/app/reducers/locations.js b/app/reducers/locations.jsindex d48888930..4e1da8a1e 100644--- a/app/reducers/locations.js+++ b/app/reducers/locations.js@@ -49,7 +49,8 @@ export type Location = {isDefault: boolean,isReadOnly?: boolean,watchForChanges?: boolean,- persistIndex?: boolean+ persistIndex?: boolean,+ fullTextIndex?: boolean};export const initialState = [];@@ -79,20 +80,9 @@ export default (state: Array<Location> = initialState, action: Object) => {return [...state,{+ ...action.location,uuid: action.location.uuid || uuidv1(),- type: action.location.type,- name: action.location.name,- paths: action.location.paths,- accessKeyId: action.location.accessKeyId,- secretAccessKey: action.location.secretAccessKey,- bucketName: action.location.bucketName,- region: action.location.region,- perspective: action.location.perspective,creationDate: new Date().toJSON(),- isDefault: action.location.isDefault,- isReadOnly: action.location.isReadOnly,- persistIndex: action.location.persistIndex,- watchForChanges: action.location.watchForChanges,}];}@@ -177,6 +167,7 @@ export const actions = {dispatch: (actions: Object) => void) => {dispatch(actions.changeLocation(location));+ dispatch(AppActions.openLocation(location));dispatch(AppActions.setReadOnlyMode(location.isReadOnly || false));},changeLocation: (location: Location) => ({diff --git a/app/services/electron-io.js b/app/services/electron-io.jsindex ee8a4a5fd..a5ba857cd 100644--- a/app/services/electron-io.js+++ b/app/services/electron-io.js@@ -19,7 +19,11 @@import fsextra from 'fs-extra';import winattr from 'winattr';-import { extractParentDirectoryPath, getMetaDirectoryPath } from '../utils/paths';+import {+ extractParentDirectoryPath,+ getMetaDirectoryPath,+ // extractFileExtension+} from '../utils/paths';import { arrayBufferToBuffer } from '../utils/misc';import AppConfig from '../config';import PlatformIO from './platform-io';@@ -27,6 +31,7 @@ import TrayIcon from '../assets/icons/trayIcon.png';// import TrayIconWin from '../assets/icons/trayIcon.ico';import TrayIcon2x from '../assets/icons/[email protected]';import TrayIcon3x from '../assets/icons/[email protected]';+import { Pro } from '../pro';export default class ElectronIO {electron: Object;@@ -205,18 +210,19 @@ export default class ElectronIO {console.error('Generating tree for ' + dirPath + ' failed ' + ex);}};- // console.log(JSON.stringify(directoyTree));+ // console.log(JSON.stringify(directoryTree));return generateDirectoryTree(directoryPath);};- createDirectoryIndexInWorker = (directoryPath: string): Promise<any> => {+ createDirectoryIndexInWorker = (directoryPath: string, extractText: boolean): Promise<any> => {return new Promise((resolve, reject) => {if (this.isWorkerAvailable()) {const timestamp = new Date().getTime().toString();this.workerWindow.webContents.send('worker', {id: timestamp,action: 'createDirectoryIndex',- path: directoryPath+ path: directoryPath,+ extractText});this.ipcRenderer.once(timestamp, (event, data) => {// console.log('Answer from worker recieved ' + data.result);@@ -247,7 +253,8 @@ export default class ElectronIO {listDirectoryPromise = (path: string,- lite: boolean = true+ lite: boolean = true,+ extractTextContent: boolean = false): Promise<Array<Object>> => new Promise(resolve => {const enhancedEntries = [];let entryPath;@@ -292,7 +299,7 @@ export default class ElectronIO {containsMetaFolder = true;}- // Read tsm.json from subfolders+ // Read tsm.json from sub foldersif (!eentry.isFile && !lite) {const folderMetaPath =eentry.path +@@ -303,18 +310,28 @@ export default class ElectronIO {try {const folderMeta = this.fs.readJsonSync(folderMetaPath);eentry.meta = folderMeta;- // console.log('Succes reading meta folder file ' + folderMetaPath);+ // console.log('Success reading meta folder file ' + folderMetaPath);} catch (err) {// console.log('Failed reading meta folder file ' + folderMetaPath);}}+ const fileName = eentry.name.toLowerCase();+ if (+ extractTextContent && eentry.isFile &&+ Pro && Pro.Indexer && Pro.Indexer.extractTextContent &&+ (fileName.endsWith('.txt') || fileName.endsWith('.md') || fileName.endsWith('.html'))+ ) {+ const fileContent = this.fs.readFileSync(eentry.path, 'utf8');+ eentry.textContent = Pro.Indexer.extractTextContent(fileName, fileContent);+ }+if (window.walkCanceled) {resolve(enhancedEntries);return;}} catch (e) {- console.warn('Can not load properties for: ' + entryPath);+ console.warn('Can not load properties for: ' + entryPath + ' ' + e);}enhancedEntries.push(eentry);});