getSearchQueryString: add "exact" option to include surrounding quotes.
This commit is contained in:
parent
dc06e2da99
commit
2cc049bb83
3 changed files with 4 additions and 1 deletions
1
flow-typed/search.js
vendored
1
flow-typed/search.js
vendored
|
@ -17,6 +17,7 @@ declare type SearchOptions = {
|
|||
SORT: string,
|
||||
SORT_ACCENDING: string,
|
||||
SORT_DESCENDING: string,
|
||||
EXACT: string,
|
||||
};
|
||||
|
||||
declare type SearchState = {
|
||||
|
|
|
@ -24,4 +24,5 @@ export const SEARCH_OPTIONS = {
|
|||
SORT: 'sort_by',
|
||||
SORT_ACCENDING: '^release_time',
|
||||
SORT_DESCENDING: 'release_time',
|
||||
EXACT: 'exact',
|
||||
};
|
||||
|
|
|
@ -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}`,
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue