Coder Social home page Coder Social logo

vuestorefront / storefront-query-builder Goto Github PK

View Code? Open in Web Editor NEW
7.0 29.0 21.0 164 KB

ElasticSearch Query builder from the abstract "SearchQuery" object used by storefront-api, vue-storefront-api and vue-storefront projects

License: MIT License

JavaScript 0.39% TypeScript 99.61%
integrations-team

storefront-query-builder's Introduction

storefront-query-builder

Stay connected

GitHub Repo stars Twitter Follow YouTube Channel Subscribers Discord

ElasticSearch Query builder from the abstract "SearchQuery" object used by storefront-api, alokai-api and alokai projects.

The idea is, that the user can create the query in a pretty abstract way and get the ElasticSearch or potentially different query in return. Some nice extension ideas could be to add mongodb support or SQL support as well.

Example usage:

import { SearchQuery, elasticsearch } from 'storefront-query-builder'
import bodybuilder from 'bodybuilder'
const searchQuery = new SearchQuery()
searchQuery = searchQuery.applyFilter({key: 'parent_id', value: {'eq': 125 }})
const elasticSearchQuery = await elasticsearch.buildQueryBodyFromSearchQuery({ config, queryChain: bodybuilder(), searchQuery })
// send the `elasticSearchQuery` to ElasticSearch instance

More on storefront-api More on alokai

storefront-query-builder's People

Contributors

alat avatar bloodf avatar cewald avatar dependabot[bot] avatar fifciu avatar filrak avatar olbix avatar pkarw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storefront-query-builder's Issues

filter by another field

Hi,
is it possible with this query builder to create filters that can compare with another field value?
like:

query.applyFilter({ key: 'special_price', value: { 'lt': "price" } })
query.applyFilter({ key: 'special_price', value: { lt: 'price.value' } })
query.applyFilter({ key: 'special_price', value: { lt: 'doc['price'].value' } })

None of above do work

Does query builder supports search attribute by text?

Hello!
Does query builder supports search attribute by text?

In vue storefront im using for example
ProductsQuery = ProductsQuery.applyFilter({ key: 'name', value: 'Test' })
And it doesn't return any item
Maybe I must add it to vsf-api schema (type=keyword)? rebuild db?

It generates
{ "query": { "bool": { "filter": { "terms": { "name": [ "Test" ] } } } } }

I checked in elasticvue manually - this request really return 0 items. What to do?

Write unit tests

What to do:

  • Install & configure JestJS
  • Write unit tests with 100% coverage

Allow aggregations

While trying to use SearchQuery to build queries for custom entities, it does not provide a way for me to add aggregations to the queries. Previously when using bodyBuilder we were requesting aggregations on certain queries for custom entity types using query = query.aggregation('terms', 'ratings.value') for example (for reviews/ratings in this example). However, I can't accomplish this aggregation using SearchQuery.

I see that aggregations are added in the core code of SearchQuery to add aggregations under a very specific condition (specifically must be in 'catalog' scope), but there is no way to add our own aggregation requests.

Add extensibility features

It would be awesome if the users can extend the way we build queries (eg. adding new operators and transformations). The easiest way would be to give the developers a way to inject their own filter transformers/mappers to the: buildQueryBodyFromSearchQuery

missing `_appliedSort` when calling `buildQueryBodyFromFilterObject`

Here https://github.com/DivanteLtd/storefront-query-builder/blob/master/src/elasticsearch/index.ts#L77 needs to be added _appliedSort because right now it throws error. Also maybe we should add here https://github.com/DivanteLtd/storefront-query-builder/blob/master/src/types/SearchQuery.ts#L18-L21 fallback values? ๐Ÿค”

    this._availableFilters = queryObj._availableFilters || []
    this._appliedFilters = queryObj._appliedFilters || []
    this._appliedSort = queryObj._appliedSort || []
    this._searchText = queryObj._searchText || []

Method to remove applied filters.

Hey Team,

let test = new searchQuery();
test.applyFilter({ filter values});

is there any specific method to remove the applied filter or empty the array later.

Thanks,

Use ES6 target instead of ES5

Hi team,

First of all, kudos to you all for contributing such an amazing library.

I am using it in Ionic 5/ Angular apps to generate elastic search queries. I noticed the following warning when using it

[ng] Warning: /xxxx.ts depends on 'storefront-query-builder'. CommonJS or AMD dependencies can cause optimization bailouts.
[ng] For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

I think if we build it as ES6 modules instead of ES5, we have the advantage of having tree shaking which can help to reduce the JavaScript payload.

WDYAT?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.