Skip to content

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

improvements in search (#1860)

Stanimire80ba0c2a39f
diff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsx
index 2eb025fc9..55152acc4 100644
--- a/app/components/SearchAutocomplete.tsx
+++ b/app/components/SearchAutocomplete.tsx
@@ -1430,7 +1430,7 @@ function SearchAutocomplete(props: Props) {
onClose={handleClose}*/
filterOptions={(options: Array<SearchOptionType>, state: any) => {
const filteredOptions = options.filter(option => {
- return option.label.indexOf(state.inputValue) > -1;
+ return option.label.toLowerCase().indexOf(state.inputValue.toLowerCase()) > -1;
});
if (filteredOptions.length === 0 && !haveEmptyAction()) {
isOpen.current = false;
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index 22857c01c..4e079889f 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -181,7 +181,7 @@ function GridPerspective(props: Props) {
: defaultSettings.orderBy
);
const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(
- props.directoryContent
+ props.searchResultsCount < 0 ? props.directoryContent : GlobalSearch.results
);
const layoutType = useRef<string>(
settings && settings.layoutType
@@ -282,14 +282,39 @@ function GridPerspective(props: Props) {
useEffect(() => {
if (!firstRender) {
- sortedDirContent.current = sortByCriteria(
- props.directoryContent,
- sortBy.current,
- orderBy.current
- );
+ if (props.searchResultsCount < 0) {
+ // not in search mode
+ sortedDirContent.current = sortByCriteria(
+ props.directoryContent,
+ sortBy.current,
+ orderBy.current
+ );
+ } else {
+ if (sortBy.current === 'byName') {
+ // don't sort search results by Name it is sorted by relevance
+ sortedDirContent.current = GlobalSearch.results;
+ } else {
+ sortedDirContent.current = sortByCriteria(
+ props.searchFilter
+ ? GlobalSearch.results.filter(entry =>
+ entry.name
+ .toLowerCase()
+ .includes(props.searchFilter.toLowerCase())
+ )
+ : GlobalSearch.results,
+ sortBy.current,
+ orderBy.current
+ );
+ }
+ }
forceUpdate();
}
- }, [props.directoryContent, sortBy.current, orderBy.current]);
+ }, [
+ // props.directoryContent,
+ props.searchResultsCount,
+ sortBy.current,
+ orderBy.current
+ ]);
useEffect(() => {
if (!firstRender) {
@@ -599,14 +624,10 @@ function GridPerspective(props: Props) {
.filter(fsEntry => fsEntry.isFile)
.map(fsentry => fsentry.path)
: [];
- const sortedDirectories =
- props.searchResultsCount < 0 // not in search mode
- ? sortedDirContent.current.filter(entry => !entry.isFile)
- : [];
- const sortedFiles =
- props.searchResultsCount < 0 // not in search mode
- ? sortedDirContent.current.filter(entry => entry.isFile)
- : GlobalSearch.results;
+ const sortedDirectories = sortedDirContent.current.filter(
+ entry => !entry.isFile
+ );
+ const sortedFiles = sortedDirContent.current.filter(entry => entry.isFile);
const locationPath = props.currentLocation
? PlatformIO.getLocationPath(props.currentLocation)
: '';
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 0a1a92b76..d04fb3b33 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -557,7 +557,7 @@ export default (state: any = initialState, action: any) => {
GlobalSearch.results = [];
return {
...state,
- searchResultsCount: -1,
+ // searchResultsCount: -1,
searchMode: true,
searchFilter: undefined,
isLoading: false