vuex-orm / plugin-search

Vuex ORM plugin for adding fuzzy search feature through model entities.
MIT License
42 stars 8 forks source link

Does this work with nested fields and related models? #19

Open dschreij opened 3 years ago

dschreij commented 3 years ago

Hi there. I have a model which includes relationships. I include relationship data with the .with() function. Even though fuse says it supports search of nested fields using the dot notation (https://fusejs.io/examples.html#nested-search), the neste fields of my model do not seem to be picked up.

const inquiries = computed(() => {
  const query = Inquiry.query()
    .has('shipment')
    .with('shipment.origin|destination')
    .with('user')
    .orderBy('created_at', 'desc')
  if (searchterm.value?.length > 2) {
    query.search(searchterm.value, {
      keys: ['status', 'shipment.hubspot_deal_id', 'user.first_name', 'user.last_name']
    })
  }
  return query.get()
})

If I search the status field. It appears to be working correctly. But if I try to search a user by first name or last name, the search result turns up empty.

So I guess my questions are:

bpuig commented 3 years ago

For me dot notation does not work either, but you can:

.has('shipment', (query) => {
  if (searchterm.value?.length > 2) {
    query.search(searchterm.value, {
      keys: ['hubspot_deal_id']
    })
  }
})

Form me it's even better than dot because I can find more easily where I'm searching