Skip to content

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

fix fullText search (#1526)

Stanimir18de1f197065
diff --git a/app/components/dialogs/CreateEditLocationDialog.tsx b/app/components/dialogs/CreateEditLocationDialog.tsx
index 7c30513b9..51da63f7a 100644
--- a/app/components/dialogs/CreateEditLocationDialog.tsx
+++ b/app/components/dialogs/CreateEditLocationDialog.tsx
@@ -59,6 +59,8 @@ import InfoIcon from '-/components/InfoIcon';
import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';
import { actions as LocationActions } from '-/reducers/locations';
import { getPersistTagsInSidecarFile } from '-/reducers/settings';
+import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
+import { actions as LocationIndexActions } from '-/reducers/location-index';
const styles: any = theme => ({
formControl: {
@@ -76,6 +78,7 @@ interface Props {
addLocation: (location: TS.Location, openAfterCreate?: boolean) => void;
editLocation?: (location: TS.Location) => void;
isPersistTagsInSidecar: boolean;
+ createLocationIndex: (location: TS.Location) => void;
}
const CreateEditLocationDialog = (props: Props) => {
@@ -176,6 +179,11 @@ const CreateEditLocationDialog = (props: Props) => {
boolean
>(false);
+ const [
+ isFullTextIndexConfirmDialogOpened,
+ setFullTextIndexConfirmDialogOpened
+ ] = useState<boolean>(false);
+
const firstRender = useFirstRender();
function changeMaxIndexAge(ageInMinutes) {
@@ -470,9 +478,12 @@ const CreateEditLocationDialog = (props: Props) => {
data-tid="changeFullTextIndex"
name="fullTextIndex"
checked={fullTextIndex}
- onChange={(event: ChangeEvent<HTMLInputElement>) =>
- setFullTextIndex(event.target.checked)
- }
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
+ setFullTextIndex(event.target.checked);
+ if (event.target.checked) {
+ setFullTextIndexConfirmDialogOpened(true);
+ }
+ }}
/>
}
label={
@@ -482,6 +493,26 @@ const CreateEditLocationDialog = (props: Props) => {
</>
}
/>
+ {isFullTextIndexConfirmDialogOpened && location && (
+ <ConfirmDialog
+ open={isFullTextIndexConfirmDialogOpened}
+ onClose={() => {
+ setFullTextIndexConfirmDialogOpened(false);
+ }}
+ title={i18n.t('core:confirm')}
+ content={i18n.t('core:fullTextIndexRegenerate')}
+ confirmCallback={result => {
+ if (result) {
+ props.createLocationIndex(location);
+ } else {
+ setFullTextIndexConfirmDialogOpened(false);
+ }
+ }}
+ cancelDialogTID="cancelSaveBeforeCloseDialog"
+ confirmDialogTID="confirmSaveBeforeCloseDialog"
+ confirmDialogContentTID="confirmDialogContent"
+ />
+ )}
<FormControlLabel
className={classes.formControl}
labelPlacement="start"
@@ -788,7 +819,8 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- addLocation: LocationActions.addLocation
+ addLocation: LocationActions.addLocation,
+ createLocationIndex: LocationIndexActions.createLocationIndex
},
dispatch
);
diff --git a/app/components/menus/LocationContextMenu.tsx b/app/components/menus/LocationContextMenu.tsx
index 9d88b193d..cb681b832 100644
--- a/app/components/menus/LocationContextMenu.tsx
+++ b/app/components/menus/LocationContextMenu.tsx
@@ -31,7 +31,6 @@ import CloseIcon from '@material-ui/icons/Close';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { actions as LocationActions } from '-/reducers/locations';
-import PlatformIO from '-/services/platform-io';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import i18n from '-/services/i18n';
import { actions as AppActions } from '-/reducers/app';
@@ -43,14 +42,8 @@ import { locationType } from '-/utils/misc';
interface Props {
setEditLocationDialogOpened: (open: boolean) => void;
setDeleteLocationDialogOpened: (open: boolean) => void;
- createDirectoryIndex: (
- path: string,
- fullTextIndex: boolean,
- isCurrentLocation: boolean,
- locationID: string
- ) => void;
+ createLocationIndex: (location: TS.Location) => void;
selectedLocation: TS.Location;
- isCurrentLocation: (uuid: string) => boolean;
moveLocationUp: (locationId: string) => void;
moveLocationDown: (locationId: string) => void;
showInFileManager: (path: string) => void;
@@ -63,36 +56,7 @@ interface Props {
const LocationContextMenu = (props: Props) => {
const indexLocation = () => {
props.setLocationDirectoryContextMenuAnchorEl(null);
- const { createDirectoryIndex, selectedLocation } = props;
- /* const isCurrentLocation =
- selectedLocation &&
- selectedLocation.uuid &&
- selectedLocation.uuid === currentLocationId; */
- const isCurrentLocation =
- selectedLocation && props.isCurrentLocation(selectedLocation.uuid);
- if (selectedLocation.type === locationType.TYPE_CLOUD) {
- PlatformIO.enableObjectStoreSupport(selectedLocation)
- .then(() => {
- createDirectoryIndex(
- getLocationPath(selectedLocation),
- selectedLocation.fullTextIndex,
- isCurrentLocation,
- selectedLocation.uuid
- );
- return true;
- })
- .catch(() => {
- PlatformIO.disableObjectStoreSupport();
- });
- } else if (selectedLocation.type === locationType.TYPE_LOCAL) {
- PlatformIO.disableObjectStoreSupport();
- createDirectoryIndex(
- getLocationPath(selectedLocation),
- selectedLocation.fullTextIndex,
- isCurrentLocation,
- selectedLocation.uuid
- );
- }
+ props.createLocationIndex(props.selectedLocation);
};
const { selectedLocation } = props;
@@ -241,8 +205,7 @@ const LocationContextMenu = (props: Props) => {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- createDirectoryIndex: LocationIndexActions.createDirectoryIndex,
- isCurrentLocation: AppActions.isCurrentLocation,
+ createLocationIndex: LocationIndexActions.createLocationIndex,
moveLocationUp: LocationActions.moveLocationUp,
moveLocationDown: LocationActions.moveLocationDown,
showInFileManager: AppActions.showInFileManager,
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index ff52fad5c..6f97c5d7f 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -33,8 +33,8 @@
"editTagGroupNewName": "Tag Group Name",
"createTagGroupTitle": "Create Tag Group",
"createTagGroupName": "Tag Group Name",
+ "fullTextIndexRegenerate": "Index for this location must be regenerated before you can perform fullText search. Do you want to regenerate index now?",
"createNewDirectoryTitle": "Create New Directory",
-
"createNewDirectoryTitleName": "New Directory Name",
"deleteDirectoryTitleConfirm": "Confirm Delete Directory",
"deleteDirectoryContentConfirm": "Do you want to delete the directory '{{dirPath}}' ?",
diff --git a/app/package-template.json b/app/package-template.json
index 25a0fb3df..38d314cf4 100644
--- a/app/package-template.json
+++ b/app/package-template.json
@@ -5,6 +5,6 @@
"nodeDependencies": {
"@tagspaces/extensions": "1.0.4",
"sharp": "^0.29.2",
- "@tagspaces/tagspaces-ws": "^1.0.22"
+ "@tagspaces/tagspaces-ws": "^1.0.25"
}
}
diff --git a/app/package.json b/app/package.json
index 88dc06740..93e32cea1 100644
--- a/app/package.json
+++ b/app/package.json
@@ -15,6 +15,6 @@
"dependencies": {
"@tagspaces/extensions": "1.0.4",
"sharp": "^0.29.2",
- "@tagspaces/tagspaces-ws": "^1.0.22"
+ "@tagspaces/tagspaces-ws": "^1.0.25"
}
}
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index c88ed7216..5c158ab6f 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -215,6 +215,42 @@ export const actions = {
dispatch(actions.indexDirectoryFailure(err));
});
},
+ createLocationIndex: (location: TS.Location) => (
+ dispatch: (actions: Object) => void,
+ getState: () => any
+ ) => {
+ if (location) {
+ const { currentLocationId } = getState().app;
+ const isCurrentLocation = currentLocationId === location.uuid;
+ if (location.type === locationType.TYPE_CLOUD) {
+ PlatformIO.enableObjectStoreSupport(location)
+ .then(() => {
+ dispatch(
+ actions.createDirectoryIndex(
+ getLocationPath(location),
+ location.fullTextIndex,
+ isCurrentLocation,
+ location.uuid
+ )
+ );
+ return true;
+ })
+ .catch(() => {
+ PlatformIO.disableObjectStoreSupport();
+ });
+ } else if (location.type === locationType.TYPE_LOCAL) {
+ PlatformIO.disableObjectStoreSupport();
+ dispatch(
+ actions.createDirectoryIndex(
+ getLocationPath(location),
+ location.fullTextIndex,
+ isCurrentLocation,
+ location.uuid
+ )
+ );
+ }
+ }
+ },
createLocationsIndexes: (extractText: boolean = true) => (
dispatch: (actions: Object) => void,
getState: () => any
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 3a5a32db8..3fd21da86 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -505,10 +505,13 @@ export function createDirectoryIndex(
// eslint-disable-next-line prefer-destructuring
loadTextFilePromise = PlatformIO.loadTextFilePromise;
}
-
+ const mode = ['extractThumbPath'];
+ if (extractText) {
+ mode.push('extractTextContent');
+ }
return createIndex(
param,
- ['extractThumbPath'],
+ mode,
ignorePatterns,
listDirectoryPromise,
loadTextFilePromise
diff --git a/package.json b/package.json
index 142d34263..5660a873a 100644
--- a/package.json
+++ b/package.json
@@ -152,7 +152,7 @@
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.57",
"@material-ui/pickers": "^3.2.10",
- "@tagspaces/tagspaces-platforms": "^1.0.54",
+ "@tagspaces/tagspaces-platforms": "^1.0.55",
"aws-amplify": "^3.3.27",
"aws-sdk": "^2.984.0",
"babel-polyfill": "^6.26.0",
diff --git a/yarn.lock b/yarn.lock
index 47715e1a2..4b6933fbf 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3362,10 +3362,10 @@
dependencies:
defer-to-connect "^1.0.1"
-"@tagspaces/tagspaces-platforms@^1.0.54":
- version "1.0.54"
- resolved "https://registry.yarnpkg.com/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-1.0.54.tgz#cfb67def5e341ead659086618452f9599b724a6f"
- integrity sha512-6/AhsTTg0SCfz+HjpMos1WbWQ/3nXXf/z1q2eq6h4UR/vGqdH6Y8FtcnzpaD8a0n0oQ6vi1DZqDxq36ukmv5ww==
+"@tagspaces/tagspaces-platforms@^1.0.55":
+ version "1.0.55"
+ resolved "https://registry.yarnpkg.com/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-1.0.55.tgz#d9344de6339634822a921b2a4d943b4ddaff15a4"
+ integrity sha512-obeFYCjhlT2MpgBM/FoKU1O2j2BY2kyhEtjaXvhfouTNvfXgmTVU2TpUkv6rlTb7VddZyRGKjY4DCwSZmSuqyQ==
"@testim/chrome-version@^1.0.7":
version "1.0.7"