Skip to content
This repository was archived by the owner on Jun 5, 2024. It is now read-only.

Conversation

@cewald
Copy link

@cewald cewald commented Apr 7, 2020

In order to the PR #4 (comment) and #3, we decided to give a more extensible approach in adding features to the storefront-query-builder by doing some refactoring.

I refactored the src/elasticsearch/index.ts and put the logic into a class to make it more read- and extendable. I also added the following features:

  • Add applySort method to SearchQuery to add more complex, custom sorts from SearchQuery
  • Add customFilters option to buildQueryBodyFromSearchQuery to be able to extend SearchQuery by custom filters
  • Add or, nor and nin filters to baseFilters
  • Refactor buildQueryBodyFromSearchQuery into more modular class – The goal was to have more readable code and be able to extend the base filter functions in a more logical way
  • Added some eslint and typescript improvements for better coding experience

There are some pitfalls and thoughts about backwards compatibility to do yet:

  • The unit tests of the VSF will fail with this despite the new _applySort property in SearchQuery – this is really easy to fix, but would appear in each test running against old code
  • The API would need an extension to somehow support the new customFilters catalog-endpoint-wise without a need to overwrite this endpoint
  • The api-search-query adapter in the Vue Storefront will need some small updates for the new sorting options

So it would be a good idea to manage this changes under a new version number to support older systems by the current version and just use this version from the current VSF/API develop branches on as a new version.

This is currently in progress and not much tested – but please give me some feedback if I don't head in a completely wrong direction.

cewald added 4 commits April 6, 2020 13:43
* Add `applySort` to `SearchQuery`
* Add `customFilters` to `buildQueryBodyFromSearchQuery`
* Add `or`, `nor` and `nin` filters
* Refactor `buildQueryBodyFromSearchQuery` into more modular class
cewald added 5 commits April 7, 2020 10:35
cewald added 3 commits April 7, 2020 18:21
… them mutable in custom- and base-filters

* Also make `catalogFilterBuilder` more variable
* Export new class to `body.ts`
* Add documentation using JSDoc
* Use `for` in `applyBaseFilters` to be able to break it
@cewald
Copy link
Author

cewald commented Apr 8, 2020

I have tested it a bit now and it seems to work fine.
I needed to make some changes at the API and VSF to make it work.

Changes for vue-storefront - vuestorefront/vue-storefront#4234:

  • Update the Unit-Tests to accept the SearchQuery object
  • Update api-search-query search-adapter to support new storefront-query-builder sorting
  • Connect new branch or npm version of storefront-query-builder
  • Update Docs – add a recipe on how to add a custom filter

Changes for vue-storefront-api - vuestorefront/vue-storefront-api#429:

  • I've added a helper that searches for specific filter classes in enabled extension folders and adds them to the catalog endpoint – this could be easily implemented on other ES queries as well this way
  • Update bodybuilder package to 2.2.21 to be able to use the clone method
  • Connect new branch or npm version of storefront-query-builder

Changes for storefront-api - vuestorefront/storefront-api#51

  • I've added a helper that searches for specific filter classes in enabled extension folders and adds them to the catalog endpoint – this could be easily implemented on other ES queries as well this way
  • Update bodybuilder package to 2.2.21 to be able to use the clone method
  • Connect new branch or npm version of storefront-query-builder

I will open up two PR's in the repos and connect this ticket.

@gibkigonzo
Copy link
Contributor

Thanks, this looks great! :)

@cewald cewald changed the title Refactor elasticsearch module for modular and extensible filter handling [WIP] Refactor elasticsearch module for modular and extensible filter handling Apr 8, 2020
@pkarw pkarw merged commit 70cca0d into vuestorefront:master Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants