getSearchQueryString: add "exact" option to include surrounding quotes.

This commit is contained in:
infinite-persistence 2021-03-23 16:55:37 +08:00 committed by Sean Yesmunt
parent dc06e2da99
commit 2cc049bb83
3 changed files with 4 additions and 1 deletions

View file

@ -17,6 +17,7 @@ declare type SearchOptions = {
SORT: string,
SORT_ACCENDING: string,
SORT_DESCENDING: string,
EXACT: string,
};
declare type SearchState = {

View file

@ -24,4 +24,5 @@ export const SEARCH_OPTIONS = {
SORT: 'sort_by',
SORT_ACCENDING: '^release_time',
SORT_DESCENDING: 'release_time',
EXACT: 'exact',
};

View file

@ -34,9 +34,10 @@ export function updateQueryParam(uri: string, key: string, value: string) {
export const getSearchQueryString = (query: string, options: any = {}) => {
const FORCE_FREE_ONLY = SIMPLE_SITE;
const isSurroundedByQuotes = (str) => str[0] === '"' && str[str.length - 1] === '"';
const encodedQuery = encodeURIComponent(query);
const queryParams = [
`s=${encodedQuery}`,
options.exact && !isSurroundedByQuotes(encodedQuery) ? `s="${encodedQuery}"` : `s=${encodedQuery}`,
`size=${options.size || DEFAULT_SEARCH_SIZE}`,
`from=${options.from || DEFAULT_SEARCH_RESULT_FROM}`,
];