Skip to content

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

improving global search

Ilian Sapundshiev611a4e17a9f6
diff --git a/app/components/Search.tsx b/app/components/Search.tsx
index 4de5c7cb3..d9681b4ac 100644
--- a/app/components/Search.tsx
+++ b/app/components/Search.tsx
@@ -295,7 +295,9 @@ class Search extends React.Component<Props, State> {
event: React.MouseEvent<HTMLElement>,
boxing: 'location' | 'folder' | 'global'
) => {
- this.setState({ searchBoxing: boxing });
+ this.setState(prevState => ({
+ searchBoxing: boxing === null ? prevState.searchBoxing : boxing
+ }));
};
executeSearch = () => {
@@ -423,12 +425,9 @@ class Search extends React.Component<Props, State> {
>
{i18n.t('folder')}
</ToggleButton>
- <ToggleButton
- value="global"
- title={i18n.t('searchInAllLocations')}
- >
+ <ToggleButton disabled={!Pro} value="global">
{i18n.t('globalSearch')}
- <sub style={{ color: 'red' }}>BETA</sub>
+ <sub>{Pro ? ' BETA' : ' PRO'}</sub>
</ToggleButton>
</ToggleButtonGroup>
</FormControl>
diff --git a/app/components/TagsSelect.tsx b/app/components/TagsSelect.tsx
index 5d1364618..7cc9a8aa0 100644
--- a/app/components/TagsSelect.tsx
+++ b/app/components/TagsSelect.tsx
@@ -137,12 +137,14 @@ const TagsSelect = (props: Props) => {
options={allTags}
getOptionLabel={option => option.title}
freeSolo
+ autoSelect
+ autoComplete
value={tags}
onChange={handleTagChange}
renderTags={(value: Tag[]) =>
- value.map((tag: Tag, index: number) => (
+ value.map((tag: Tag) => (
<TagContainer
- key={tag.title + index}
+ key={uuidv1()}
tag={tag}
tagMode="remove"
handleRemoveTag={(event, cTag) => {
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index 10c0d8c24..0795112ba 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -375,7 +375,9 @@ export const actions = {
state,
state.app.currentLocationId
);
- dispatch(actions.startDirectoryIndexing());
+ dispatch(
+ AppActions.showNotification(i18n.t('core:searching'), 'default', false)
+ );
dispatch(AppActions.setSearchResults([]));
const allLocations = getLocations(state);
const locationPaths = [];
@@ -384,58 +386,72 @@ export const actions = {
});
const result = locationPaths.reduce(
(accumulatorPromise, nextPath) =>
- accumulatorPromise.then(() =>
- createDirectoryIndex(nextPath, true)
- .then(directoryIndex => {
- AppActions.showNotification(
- i18n.t('Searching:' + nextPath),
- 'default',
- true
- );
- console.log('Searching in:' + nextPath);
- Search.searchLocationIndex(directoryIndex, searchQuery)
- .then(searchResults => {
- dispatch(AppActions.appendSearchResults(searchResults));
- dispatch(AppActions.hideNotifications());
- return true;
- })
- .catch(() => {
- dispatch(AppActions.setSearchResults([]));
- dispatch(AppActions.hideNotifications());
- dispatch(
- AppActions.showNotification(
- i18n.t('core:searchingFailed'),
- 'warning',
- true
- )
- );
- });
- if (Pro && Pro.Indexer) {
- Pro.Indexer.persistIndex(
- nextPath,
- directoryIndex,
- currentLocation.type === locationType.TYPE_CLOUD
- ? '/'
- : AppConfig.dirSeparator
- );
- }
+ accumulatorPromise.then(async () => {
+ let directoryIndex = [];
+ let hasIndex = false;
+ const dirSeparator =
+ currentLocation.type === locationType.TYPE_CLOUD
+ ? '/'
+ : AppConfig.dirSeparator;
+ console.log('Searching in: ' + nextPath);
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('core:searching') + nextPath,
+ 'default',
+ true
+ )
+ );
+ if (Pro && Pro.Indexer && Pro.Indexer.hasIndex) {
+ hasIndex = await Pro.Indexer.hasIndex(nextPath);
+ }
+ if (searchQuery.forceIndexing || !hasIndex) {
+ console.log('Creating index for : ' + nextPath);
+ directoryIndex = await createDirectoryIndex(nextPath, true);
+ if (Pro && Pro.Indexer && Pro.Indexer.persistIndex) {
+ Pro.Indexer.persistIndex(nextPath, directoryIndex, dirSeparator);
+ }
+ } else if (Pro && Pro.Indexer && Pro.Indexer.loadIndex) {
+ console.log('Loading index for : ' + nextPath);
+ directoryIndex = await Pro.Indexer.loadIndex(
+ nextPath,
+ dirSeparator
+ );
+ }
+ return Search.searchLocationIndex(directoryIndex, searchQuery)
+ .then(searchResults => {
+ dispatch(AppActions.appendSearchResults(searchResults));
+ dispatch(AppActions.hideNotifications());
return true;
})
- .catch(err => {
- dispatch(actions.indexDirectoryFailure(err));
- })
- ),
+ .catch(() => {
+ dispatch(AppActions.setSearchResults([]));
+ dispatch(AppActions.hideNotifications());
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('core:searchingFailed'),
+ 'warning',
+ true
+ )
+ );
+ });
+ }),
Promise.resolve()
);
result
- .then(e => {
- dispatch(actions.indexDirectorySuccess());
- console.log('Resolution is complete!', e);
+ .then(() => {
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('Global search completed'),
+ 'default',
+ true
+ )
+ );
+ console.log('Global search completed!');
return true;
})
.catch(e => {
- console.warn('Resolution is faled!', e);
+ console.warn('Global search faled!', e);
});
},
indexDirectorySuccess: () => ({
diff --git a/app/services/search.ts b/app/services/search.ts
index 14bf521dd..5b13d8f43 100644
--- a/app/services/search.ts
+++ b/app/services/search.ts
@@ -58,6 +58,7 @@ export type SearchQuery = {
lastModified?: string;
fileSize?: string;
searchBoxing?: 'location' | 'folder';
+ forceIndexing?: boolean;
currentDirectory?: string;
tagTimePeriodFrom?: number | null;
tagTimePeriodTo?: number | null;