travis-r6s / gridsome-plugin-flexsearch

Add lightning fast search to Gridsome with FlexSearch
24 stars 7 forks source link

Results effected by searchFields order #60

Closed gilesbutler closed 3 years ago

gilesbutler commented 3 years ago

Hey @thetre97 thanks for this awesome plugin.

We're getting a really strange issue with not getting the results we expect.

When we search for "school" we expect to see 3 results but we're only getting the following 2...

CleanShot 2020-11-09 at 12 41 19@2x

I messed around trying different flexsearch options but it didn't change the results. I then tried to reorder the searchFields that we pass in by switching around title and sectorSubtitle. We then got back the third expected result but the other two results disappeared.

searchFields: [
          "sectorSubtitle",
          "title",

CleanShot 2020-11-09 at 12 42 42@2x

Here's our config ``` { use: "gridsome-plugin-flexsearch", options: { autoFetch: false, searchFields: [ "title", "sectorSubtitle", "tags", "article_description", "article", "subtitle", "name", "sectors_groups_we_fund", "sector_asset_examples", "service_detail_title", "service_detail", "team_section_title", "team_member_name", "profile_excerpt", "description", "faq_question", "search_meta", ], collections: [ { typeName: "DatoArticle", indexName: "DatoArticle", fields: ["title"], }, { typeName: "DatoFinanceOption", indexName: "DatoFinanceOption", fields: ["title"], }, { typeName: "DatoLandingPage", indexName: "DatoLandingPage", fields: ["title"], }, { typeName: "DatoSector", indexName: "DatoSector", fields: ["title"], }, { typeName: "DatoService", indexName: "DatoService", fields: ["title"], }, { typeName: "DatoTeamMember", indexName: "DatoTeamMember", fields: ["title"], }, { typeName: "DatoWebinar", indexName: "DatoWebinar", fields: ["title"], }, { typeName: "DatoFAQ", indexName: "DatoFAQ", fields: ["title"], }, ], }, }, ```

With the config above (before changing the order) I can see in flexsearch.json that school is appearing twice, once with 2 ids for the article results, and the second time with just 1 id for the eduction sector result.

I'm not sure where we're going wrong or if it's a bug/config issue. Really appreciate any help you can offer.

Thanks

travis-r6s commented 3 years ago

@gilesbutler That's very strange - not sure what the issue is there, but this plugin shouldn't affect the search indexing/results etc at all, so may be a config issue. Have you tried playing around with any of the flexsearch profile options at all? https://github.com/nextapps-de/flexsearch#presets

gilesbutler commented 3 years ago

Thanks for getting back to me @thetre97 - Yep I tried all the different flexsearch presets and they didn't change the results at all which I thought was strange.

In the end we've added a searchMeta field on all of our models in dato which the users can add a bunch of keywords too. We're now just searching on the searchMeta field and the title field. I've had to add searchMeta field before title though in the searchFields array or it doesn't work as expected 🤷‍♂️

travis-r6s commented 3 years ago

Seems this may be a flexsearch issue - see https://github.com/nextapps-de/flexsearch/issues/70 for example...

gilesbutler commented 3 years ago

Ah good find @thetre97! I didn't find that issue when searching their repo. I'll keep an eye on it.

stefandesu commented 3 years ago

Hi @thetre97, I'm the one who opened the issue on the Flexsearch repo that you mentioned. Have you found a fix for this? Or is it fixed in 0.7.0? Thanks!

travis-r6s commented 3 years ago

Hey @stefandesu I haven't, no - I hadn't looked for a fix, as I assumed it was purely a FlexSearch issue... There does seem to be some big changes in 0.7.0, so perhaps it will be...