Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions resources/js/components/Listing/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export default {
type: String,
default: window.config.index.product,
},
query: {
type: Function,
default: () => [],
},
categoryId: {
type: Number,
},
Expand Down Expand Up @@ -101,7 +97,6 @@ export default {
const config = await InstantSearchMixin.methods.getInstantSearchClientConfig.bind(this).call()

config.getBaseFilters = this.getBaseFilters
config.getQuery = this.getQuery

return config
},
Expand Down Expand Up @@ -138,19 +133,14 @@ export default {
return this.baseFilters().concat(extraFilters)
},

getQuery(query, search_attributes) {
let extraQueries = []
getQuery(query, search_attributes, config) {
let queries = InstantSearchMixin.methods.getQuery.bind(this).call(this, ...arguments)

if (this.categoryId) {
extraQueries.push(this.$root.categoryPositions(this.categoryId))
}

// __NO_QUERY__ is a temporary band-aid for https://github.com/searchkit/searchkit/pull/1407
if (query && query !== '__NO_QUERY__') {
extraQueries.push(this.relevanceQueryMatch(query, search_attributes, config?.fuzziness))
queries.push(this.$root.categoryPositions(this.categoryId))
}

return this.query().concat(extraQueries)
return queries
},

windowTitle(routeState) {
Expand Down
19 changes: 19 additions & 0 deletions resources/js/components/Search/InstantSearchMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { instantsearchMiddlewares } from '../../stores/useInstantsearchMiddlewar
import { createInsightsMiddleware } from 'instantsearch.js/es/middlewares/createInsightsMiddleware'
export default {
props: {
query: {
type: Function,
default: function (query, searchAttributes, config) {
// __NO_QUERY__ is a temporary band-aid for https://github.com/searchkit/searchkit/pull/1407
if (query && query !== '__NO_QUERY__') {
return this.relevanceQueryMatch(query, searchAttributes, config?.fuzziness)
}
Comment on lines +12 to +15
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could still move this to the getQuery function, removing the ability to remove/move the relevanceQueryMatch which hasn't been an ability yet until now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily mind this approach, but now if you want to add an extra query to this (for example, some kind of extra scoring function) you will also need to re-define this functionality inside of the prop. Seems a bit unwieldy to me for those cases.

Might be better in practice to have a prop that lets you disable the default query?

},
},
},
data: () => ({
searchkit: null,
searchClient: null,
Expand Down Expand Up @@ -45,6 +56,7 @@ export default {
})
},
},
getQuery: this.getQuery,
}
},
Expand All @@ -56,6 +68,13 @@ export default {
return instantsearchMiddlewares
},
getQuery(query, search_attributes, config) {
const esQuery = this.query(...arguments)
let queries = Array.isArray(esQuery) ? esQuery : [esQuery]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check just makes sure it's backwards compatible with the old way of returning an array of queries instead of a query on it's own

return queries.filter((q) => q)
},
relevanceQueryMatch(query, search_attributes, fuzziness = 'AUTO:4,8') {
// Copied from searchkit.js default behavior when getQuery is not defined.
const getFieldsMap = (boostMultiplier) => {
Expand Down