Skip to content

Commit

Permalink
[SDPA-3128] Added property to exclude hits. (#508)
Browse files Browse the repository at this point in the history
* [SDPA-3128] Fixed linting errors.
  • Loading branch information
GROwen authored Sep 3, 2019
1 parent dc60347 commit 5f1c12e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default (config, router, site) => ({
* @param {Array} options.qFields Array of query fields
* @param {Array} options.sFields Array of source fields
* @param {Array} options.filterFromURI Array of fields to remove from URI
* @param {Object} options.exclude (optional) Properties to exclude from hits.
* @param {String} options.exclude.type The API entity type to exclude.
* @param {String} options.exclude.field (optional) The API field_name. The API field_name. If set and a value exists, hits are excluded.
* @param {String} queryString
* @param {Int} page Used to calculate the start point for returned hits.
* @param {Object} filters filterForm arguments to refine search hits using a filter context.
Expand Down Expand Up @@ -59,7 +62,7 @@ export default (config, router, site) => ({

let from = this.getFromHit(page, options.responseSize)

const hits = await service.api.search(client, index, queryString, filters, filterFields, options.qFields, options.sFields, from, options.responseSize, sort)
const hits = await service.api.search(client, index, queryString, filters, filterFields, options.qFields, options.sFields, from, options.responseSize, sort, options.exclude)

this.updateLocParams({
q: queryString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export default ({
})
return response
},
search: async function (client, index, queryString, filters, filterFields, qFields, sFields, from, size, sort) {
search: async function (client, index, queryString, filters, filterFields, qFields, sFields, from, size, sort, exclude) {
// TODO: Add a check for node_grants and published
const computedQuery = qB.getEsQueryBody(queryString, filters, qFields)
const computedQuery = qB.getEsQueryBody(queryString, filters, qFields, exclude)

const dsl = {
from: from,
size: size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,25 @@ export default ({
* @param {Array} filters.values Values to pass to filter context.
* @param {Array} filters.fields Fields to filter values against.
* @param {Array} fields Fields to query the queryString against.
* @param {Object} exclude (optional) Properties to exclude from hits.
* @param {String} exclude.type The API entity type to exclude.
* @param {String} exclude.field (optional) The API field_name. The API field_name. If set and a value exists, hits are excluded.
*/
getEsQueryBody: function (queryString, filters, fields) {
getEsQueryBody: function (queryString, filters, fields, exclude) {
let esbResult = {}
if (queryString === false) {
esbResult = esb.boolQuery().must(esb.matchAllQuery())
} else if (exclude) {
let excludes = [
esb.termQuery('type', exclude.type)
]
if (exclude.field) {
excludes.push(esb.existsQuery(exclude.field))
}
esbResult = esb.boolQuery().must([
esb.multiMatchQuery(fields, queryString),
esb.boolQuery().mustNot(esb.boolQuery().must(excludes))
])
} else {
esbResult = esb.boolQuery().must(esb.multiMatchQuery(fields, queryString))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export default {
'title',
'type',
'url'
]
],
exclude: {
'type': 'grant',
'field': 'field_node_link'
}
}
}
},
Expand Down

0 comments on commit 5f1c12e

Please sign in to comment.