-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* configured the picture index in plugin.js, provided a hook to test meilisearch with one search term * minor correction in the config, added the necessary packages for frontend and backend * finished the search helper * plugin configuration is done, for now. The helper function should work just fine * forgot to add the config file in the last commit * Update projects/bp-gallery/src/components/views/search/SearchView.tsx Co-authored-by: Oliver Schulz <64468276+olschulz@users.noreply.github.com> * commit for fun * revert the quatsch from last commit * small change to the conscole output * small change to the conscole output * implemented the requested changes --------- Co-authored-by: Oliver Schulz <64468276+olschulz@users.noreply.github.com>
- Loading branch information
1 parent
a554b4d
commit a24e96e
Showing
8 changed files
with
269 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
projects/bp-gallery/src/components/views/search/helpers/getSearchResultPictureIds.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { MeiliSearch } from 'meilisearch'; | ||
|
||
const dateToTimeStamp = (date: string) => { | ||
return Date.parse(date) / 1000; | ||
}; | ||
|
||
const getSearchResultPictureIds = async ( | ||
{ searchTerms, searchTimes }: { searchTerms: string[]; searchTimes: string[][] }, | ||
filter: string | ||
) => { | ||
const client = new MeiliSearch({ | ||
host: 'localhost:7700', | ||
apiKey: '', | ||
}); | ||
const index = client.index('picture'); | ||
|
||
const TIME_RANGE_START = 'time_range_tag_start'; | ||
const TIME_RANGE_END = 'time_range_tag_end'; | ||
// when building a filter for meilisearch the filtered attribute always | ||
// has to come first i.e. time_range_start >= 0 works but 0 <= time_range_start does not work | ||
if (searchTimes.length !== 0) { | ||
const timeFilters = searchTimes.map( | ||
searchTime => | ||
`(${TIME_RANGE_START} >= ${dateToTimeStamp( | ||
searchTime[1] | ||
)} AND ${TIME_RANGE_END} <= ${dateToTimeStamp(searchTime[2])})` | ||
); | ||
|
||
const timeFilter = timeFilters.join(' OR '); | ||
filter = filter === '' ? timeFilter : filter.concat(' AND ', timeFilter); | ||
} | ||
|
||
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, | ||
}; | ||
const query = searchTerms.length !== 0 ? searchTerms.join(' ') : ''; | ||
const searchResult = await index.search(query, settings); | ||
return searchResult.hits; | ||
}; | ||
|
||
export default getSearchResultPictureIds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.