Skip to content

Commit

Permalink
[base] Remove empty query segments causing invalid queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Jun 5, 2019
1 parent 9fe8130 commit deadc96
Showing 1 changed file with 5 additions and 6 deletions.
Expand Up @@ -35,19 +35,18 @@ export function createWeightedSearch(types, client) {
// this is the actual search function that takes the search string and returns the hits
return function search(queryString, opts = {}) {
const terms = uniq(compact(tokenize(toLower(queryString))))
const constraints = terms.map((term, i) =>
combinedSearchPaths.map(joinedPath => `${joinedPath} match $t${i}`)
)
const constraints = terms
.map((term, i) => combinedSearchPaths.map(joinedPath => `${joinedPath} match $t${i}`))
.filter(constraint => constraint.length > 0)

const filters = [
'_type in $types',
opts.includeDrafts === false && `!(_id in path('drafts.**'))`,
...constraints.map(constraint => `(${constraint.join('||')})`)
].filter(Boolean)

const query = `*[${filters.join('&&')}][0...$limit]{_type, _id, ...select(${selections.join(
',\n'
)})}`
const selection = selections.length > 0 ? `...select(${selections.join(',\n')})` : ''
const query = `*[${filters.join('&&')}][0...$limit]{_type, _id, ${selection}}`

return client.observable
.fetch(query, {
Expand Down

0 comments on commit deadc96

Please sign in to comment.