TagSpaces is an offline, open source, document manager with tagging support
showing tags for which it is searched in the search area
Ilian Sapundshiev94af270160b3
diff --git a/app/components/Search.tsx b/app/components/Search.tsxindex d9681b4ac..9c300c983 100644--- a/app/components/Search.tsx+++ b/app/components/Search.tsx@@ -57,7 +57,8 @@ import { actions as AppActions, getDirectoryPath } from '../reducers/app';import {actions as LocationIndexActions,getIndexedEntriesCount,- isIndexing+ isIndexing,+ getSearchQuery} from '../reducers/location-index';import { getMaxSearchResults } from '../reducers/settings';import styles from './SidePanels.css';@@ -79,6 +80,8 @@ interface Props {loadDirectoryContent: (path: string) => void;openURLExternally: (url: string) => void;hideDrawer?: () => void;+ searchQuery: () => any;+ setSearchQuery: (searchQuery: SearchQuery) => void;currentDirectory: string;indexedEntriesCount: number;maxSearchResults: number;@@ -133,6 +136,18 @@ class Search extends React.Component<Props, State> {searchMenuAnchorEl: null};+ static getDerivedStateFromProps(nextProps, prevState) {+ if (nextProps.searchQuery && nextProps.searchQuery.tagsAND) {+ return {+ ...prevState,+ tagsAND: nextProps.searchQuery.tagsAND+ };+ }+ return {+ ...prevState+ };+ }+handleInputChange = event => {const { target } = event;const value =@@ -266,29 +281,40 @@ class Search extends React.Component<Props, State> {};clearSearch = () => {- this.setState(- {- textQuery: '',- tagsAND: [],- tagsOR: [],- tagsNOT: [],- searchBoxing: 'location',- fileTypes: FileTypeGroups.any,- lastModified: '',- tagTimePeriod: '',- tagTimePeriodHelper: ' ',- tagPlace: '',- tagPlaceHelper: ' ',- tagTimePeriodFrom: null,- tagTimePeriodTo: null,- tagPlaceLat: null,- tagPlaceLong: null,- tagPlaceRadius: 0,- forceIndexing: false,- fileSize: ''- },- () => this.props.loadDirectoryContent(this.props.currentDirectory)- );+ const {+ setSearchQuery,+ loadDirectoryContent,+ currentDirectory+ } = this.props;+ setSearchQuery({});+ setTimeout(() => {+ // TODO find solution without settimeout+ this.setState(+ {+ textQuery: '',+ tagsAND: [],+ tagsOR: [],+ tagsNOT: [],+ searchBoxing: 'location',+ fileTypes: FileTypeGroups.any,+ lastModified: '',+ tagTimePeriod: '',+ tagTimePeriodHelper: ' ',+ tagPlace: '',+ tagPlaceHelper: ' ',+ tagTimePeriodFrom: null,+ tagTimePeriodTo: null,+ tagPlaceLat: null,+ tagPlaceLong: null,+ tagPlaceRadius: 0,+ forceIndexing: false,+ fileSize: ''+ },+ () => {+ loadDirectoryContent(currentDirectory);+ }+ );+ }, 100);};switchSearchBoxing = (@@ -301,6 +327,11 @@ class Search extends React.Component<Props, State> {};executeSearch = () => {+ const {+ setSearchQuery,+ searchAllLocations,+ searchLocationIndex+ } = this.props;const searchQuery: SearchQuery = {textQuery: this.state.textQuery,tagsAND: this.state.tagsAND,@@ -325,10 +356,11 @@ class Search extends React.Component<Props, State> {forceIndexing: this.state.forceIndexing};console.log('Search object: ' + JSON.stringify(searchQuery));+ setSearchQuery(searchQuery);if (this.state.searchBoxing === 'global') {- this.props.searchAllLocations(searchQuery);+ searchAllLocations(searchQuery);} else {- this.props.searchLocationIndex(searchQuery);+ searchLocationIndex(searchQuery);}};@@ -750,6 +782,7 @@ class Search extends React.Component<Props, State> {function mapStateToProps(state) {return {indexing: isIndexing(state),+ searchQuery: getSearchQuery(state),currentDirectory: getDirectoryPath(state),indexedEntriesCount: getIndexedEntriesCount(state),maxSearchResults: getMaxSearchResults(state)@@ -760,6 +793,7 @@ function mapDispatchToProps(dispatch) {return bindActionCreators({searchAllLocations: LocationIndexActions.searchAllLocations,+ setSearchQuery: LocationIndexActions.setSearchQuery,searchLocationIndex: LocationIndexActions.searchLocationIndex,createLocationsIndexes: LocationIndexActions.createLocationsIndexes,loadDirectoryContent: AppActions.loadDirectoryContent,diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.tsindex 0795112ba..81b26e9d3 100644--- a/app/reducers/location-index.ts+++ b/app/reducers/location-index.ts@@ -34,6 +34,7 @@ import { Tag } from './taglibrary';import GlobalSearch from '../services/search-index';export const types = {+ SET_SEARCH_QUERY: 'SET_SEARCH_QUERY',INDEX_DIRECTORY: 'INDEX_DIRECTORY',INDEX_DIRECTORY_CLEAR: 'INDEX_DIRECTORY_CLEAR',INDEX_DIRECTORY_START: 'INDEX_DIRECTORY_START',@@ -49,11 +50,15 @@ export const types = {};export const initialState = {- isIndexing: false+ isIndexing: false,+ searchQuery: {}};export default (state: any = initialState, action: any) => {switch (action.type) {+ case types.SET_SEARCH_QUERY: {+ return { ...state, searchQuery: action.searchQuery };+ }case types.INDEX_DIRECTORY_START: {return {...state,@@ -212,6 +217,10 @@ export default (state: any = initialState, action: any) => {};export const actions = {+ setSearchQuery: (searchQuery: SearchQuery) => ({+ type: types.SET_SEARCH_QUERY,+ searchQuery+ }),startDirectoryIndexing: () => ({ type: types.INDEX_DIRECTORY_START }),cancelDirectoryIndexing: () => ({ type: types.INDEX_DIRECTORY_CANCEL }),createDirectoryIndex: (@@ -345,6 +354,7 @@ export const actions = {dispatch(AppActions.showNotification(i18n.t('core:searching'), 'default', false));+ dispatch(actions.setSearchQuery(searchQuery));setTimeout(() => {// Workaround used to show the start search notificationSearch.searchLocationIndex(GlobalSearch.index, searchQuery)@@ -375,6 +385,7 @@ export const actions = {state,state.app.currentLocationId);+ console.time('globalSearch');dispatch(AppActions.showNotification(i18n.t('core:searching'), 'default', false));@@ -406,7 +417,7 @@ export const actions = {}if (searchQuery.forceIndexing || !hasIndex) {console.log('Creating index for : ' + nextPath);- directoryIndex = await createDirectoryIndex(nextPath, true);+ directoryIndex = await createDirectoryIndex(nextPath, true); // take the last treu from location objectif (Pro && Pro.Indexer && Pro.Indexer.persistIndex) {Pro.Indexer.persistIndex(nextPath, directoryIndex, dirSeparator);}@@ -440,6 +451,7 @@ export const actions = {result.then(() => {+ console.timeEnd('globalSearch');dispatch(AppActions.showNotification(i18n.t('Global search completed'),@@ -451,6 +463,7 @@ export const actions = {return true;}).catch(e => {+ console.timeEnd('globalSearch');console.warn('Global search faled!', e);});},@@ -489,3 +502,4 @@ export const actions = {// Selectorsexport const getIndexedEntriesCount = (state: any) => GlobalSearch.index.length;export const isIndexing = (state: any) => state.locationIndex.isIndexing;+export const getSearchQuery = (state: any) => state.locationIndex.searchQuery;