Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

546 implement meilisearch as main search engine #569

Merged
merged 36 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9e9c826
integrated meilisearch into the searchview
baerlach-git Jun 21, 2023
d3404cc
added the additional dependencies and exteneded gitignore
baerlach-git Jun 21, 2023
71baf38
reset gitignore to previous state
baerlach-git Jun 21, 2023
ebb2390
started working on the advanced search
baerlach-git Jun 22, 2023
f9a0b61
startet building the filter inputs
baerlach-git Jun 23, 2023
0fec384
worked on the methods for building filters
baerlach-git Jun 25, 2023
56bdbcb
added AdvancedSearchContext
baerlach-git Jun 25, 2023
a90bdd3
filter is is now being beuilt when choosing an option in the advanced…
baerlach-git Jun 26, 2023
d2f1fa3
ruined everything
baerlach-git Jun 26, 2023
6757b95
still trash, lol
baerlach-git Jun 29, 2023
744fb91
things are starting to work
baerlach-git Jun 29, 2023
5fa9e01
filters should now be build properly
baerlach-git Jul 1, 2023
dfe8f10
improved the UI
baerlach-git Jul 2, 2023
c04c16d
more styling
baerlach-git Jul 3, 2023
3c9aea0
search results now refresh upon applying a new filter
baerlach-git Jul 4, 2023
be406ec
merged staging into local branch
baerlach-git Jul 4, 2023
1467a1c
fixed an error in the filter building methods
baerlach-git Jul 4, 2023
a69f76b
added advanced search helptooltip + minor styling
baerlach-git Jul 5, 2023
95bbaa2
configured comment, person and location indices
baerlach-git Jul 7, 2023
c4b2eb5
started adjusting advancedSearch and SearchView to accomodate multipl…
baerlach-git Jul 7, 2023
0255b66
bit more config for the new indices
baerlach-git Jul 8, 2023
46ca836
search in the comment index doesn't fully work yet, so i commented ev…
baerlach-git Jul 11, 2023
f56595a
Fix key errors
MariusDoe Jul 13, 2023
389a9ba
Fix meilisearch displayedAttributes
MariusDoe Jul 13, 2023
8d91b74
Add QueryParams type
MariusDoe Jul 12, 2023
c720868
Add idArray filters
MariusDoe Jul 12, 2023
5e652f0
Add text filtering to SearchView
MariusDoe Jul 13, 2023
3e484b7
search helper now uses api key from env
baerlach-git Jul 14, 2023
9f62cf2
removed console.logs
baerlach-git Jul 14, 2023
7899fb0
modified gallery envs
baerlach-git Jul 14, 2023
e88b707
implemented the requested changes
baerlach-git Jul 15, 2023
2abf962
updated test.yml & commented out a problematic test
baerlach-git Jul 15, 2023
6601c7f
fixed a mistake in the picture search index
baerlach-git Jul 15, 2023
e5d3452
minor changes to comment index
baerlach-git Jul 15, 2023
5e05d4f
commented out some road blocks
baerlach-git Jul 16, 2023
0fe3334
merged staging into local
baerlach-git Jul 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.vscode/**/*
!.vscode/launch.json
remote-debug-profile/**

baerlach-git marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions projects/bp-gallery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-router-config": "^5.1.1",
"react-router-dom": "^5.3.0",
"react-scroll-parallax": "^3.3.2",
"react-use-promise": "^0.5.0",
"react-use-storage-state": "^1.0.5",
"tailwindcss": "^3.2.4",
"tui-image-editor": "^3.15.3",
Expand Down
45 changes: 37 additions & 8 deletions projects/bp-gallery/src/components/views/search/SearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Location } from 'history';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import usePromise from 'react-use-promise';
import { PictureFiltersInput } from '../../../graphql/APIConnector';
import { useFlag } from '../../../helpers/growthbook';
import useBulkOperations from '../../../hooks/bulk-operations.hook';
import { HelpTooltip } from '../../common/HelpTooltip';
import PictureScrollGrid from '../../common/picture-gallery/PictureScrollGrid';
Expand Down Expand Up @@ -44,7 +47,6 @@ const SearchView = () => {

// Builds query from search params in the path
const queryParams = useMemo(() => {
// if (isAllSearchActive) {
const allSearchTerms = searchParams
.getAll(toURLSearchParam(SearchType.ALL))
.map(decodeURIComponent);
Expand All @@ -59,11 +61,32 @@ const SearchView = () => {
searchTerms: allSearchTerms.filter(searchTerm => !isValidTimeSpecification(searchTerm)),
searchTimes,
};
// }
// return convertSearchParamsToPictureFilters(searchParams);
}, [/*isAllSearchActive,*/ searchParams]);
if (import.meta.env.MODE === 'development')
getSearchResultPictureIds(queryParams, '').then(res => console.log('search results:', res));
}, [searchParams]);

const [searchResultIds, error, state] = usePromise(
async () =>
(await getSearchResultPictureIds(queryParams, '')).map(hit => (hit.id as number).toString()),
[queryParams]
);

const pictureFilter: PictureFiltersInput = useMemo(() => {
if (error) {
console.log(error);
return {};
}
return state === 'resolved' ? { id: { in: searchResultIds } } : {};
}, [searchResultIds, state, error]);
console.log(pictureFilter);
const isOldSearchActive = useFlag('old_search');

if (import.meta.env.MODE === 'development') {
// getSearchResultPictureIds(queryParams, '').then(res => console.log('search results:', res));
console.log('resultids', searchResultIds);
console.log(
ole1711 marked this conversation as resolved.
Show resolved Hide resolved
'31149 key:',
searchResultIds?.findIndex(element => element === '31149')
);
}
const { linkToCollection, bulkEdit } = useBulkOperations();

return (
Expand All @@ -84,8 +107,14 @@ const SearchView = () => {
) : (
<ShowStats>
<PictureScrollGrid
queryParams={queryParams}
isAllSearchActive={isAllSearchActive}
queryParams={isOldSearchActive ? queryParams : pictureFilter}
// if allSearch is active the custom resolver for allSearch will be used, which can only
// handle simple queryparams in the format {searchTerms:string[], searchTimes:string[][]} which
// leads to erros when we use queryparams of the type PictureFiltersInput,
// so isAllSearchactive has to be false if we want to use the Meilisearch results
// by ANDing the isAllsearchActive flag with the isOldsearchActive flag we can make sure
// the isAllSearchActive property will always be false if we want to use Meilisearch
isAllSearchActive={isOldSearchActive && isAllSearchActive}
hashbase={search}
bulkOperations={[linkToCollection, bulkEdit]}
resultPictureCallback={(pictures: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ const getSearchResultPictureIds = async (
filter = filter === '' ? timeFilter : filter.concat(' AND ', timeFilter);
}

// for reference: https://www.meilisearch.com/docs/reference/api/search
const RESULT_LIMIT = 1000;
// this makes it so only documents that match all of the query terms are returned
const MATCHING_STRATEGY = 'all';

const settings = {
limit: RESULT_LIMIT,
showMatchesPosition: true,
matchingStrategy: MATCHING_STRATEGY,
filter: filter,
};
Expand Down
1 change: 1 addition & 0 deletions projects/bp-gallery/src/helpers/growthbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type AppFeatures = {
};
geopictures_collection_id: string;
start_view_default_tab_index: number;
old_search: boolean;
baerlach-git marked this conversation as resolved.
Show resolved Hide resolved
};

export type FeatureId = keyof AppFeatures;
Expand Down
5 changes: 5 additions & 0 deletions projects/bp-gallery/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7126,6 +7126,11 @@ react-transition-group@^4.4.5:
loose-envify "^1.4.0"
prop-types "^15.6.2"

react-use-promise@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/react-use-promise/-/react-use-promise-0.5.0.tgz#1abe26f73a9d55415c081ef5be74087840bac0a8"
integrity sha512-kpmnwDsXILLsEe4lxMT2iaJKQq1Wt4KuW2t6YPXwulAWSvnqwPAlj8wrRMQ5d/0+SutKR2qk41yJpeaV49bvUQ==

react-use-storage-state@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/react-use-storage-state/-/react-use-storage-state-1.0.5.tgz#9b63690d59181ddb6b84d2dfa5fec86087b57eec"
Expand Down
1 change: 1 addition & 0 deletions projects/bp-strapi/config/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ module.exports = ({ env }) => ({
return transformedEntry;
},
settings: {
//for reference: https://www.meilisearch.com/docs/reference/api/settings
displayedAttributes: ["id"],
// the order of the attributes in searchableAttributes determines the priorization
// of search results i.e. a match in the first searchable attribute will always outrank a match in any other searchable attribute
Expand Down