Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ using searchQuery object as a search layer + GraphQl support #1616

Merged
merged 80 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
5c2d83b
MTH-250 Add base graphql server and resolvers to the VSF core
yuriboyko Jul 13, 2018
ad3457d
MTH-250 Fix ES client config and export
yuriboyko Jul 13, 2018
28c675e
MTH-250 Add Apollo client with config
yuriboyko Jul 16, 2018
4e99962
MTH-250 Add phoenix Apollo Test theme with test graphql requests
yuriboyko Jul 16, 2018
59a920d
MTH-250 add graphql and gql file loader, add schemas/resolvers to core
VladimirPlastovets Jul 16, 2018
364c46f
MTH-250 apply autocomplete via Apollo graphql
VladimirPlastovets Jul 16, 2018
89bdaf7
MTH-250 remove server part
VladimirPlastovets Jul 16, 2018
874c87b
MTH-250 fix apollo client connection
VladimirPlastovets Jul 16, 2018
35d0f8b
MTH-250 add images to autocomplete block
VladimirPlastovets Jul 16, 2018
0f19314
MTH-250 Add test search via graphql in the search function
yuriboyko Jul 17, 2018
1c2ca31
Revert MTH-250 Add test search via graphql in the search function
yuriboyko Jul 18, 2018
e40be1c
MTH-250 Add new dispatcher and graphql search lib
yuriboyko Jul 18, 2018
539b6ba
MTH-250 apply fix for response source
VladimirPlastovets Jul 18, 2018
e5ae5d3
MTH-250 fix fue to changes in graphql schema
VladimirPlastovets Jul 23, 2018
e95a1f2
MTH-250 Rough update of search functionality required for merging wor…
yuriboyko Jul 30, 2018
0074680
MTH-250 Improve new search query functionality with filtering
yuriboyko Aug 1, 2018
5eb04f4
MTH-250 update graphql adapter with quiery containing filters
yuriboyko Aug 1, 2018
7487750
MTH-250 update graphql query, improve filtering
yuriboyko Aug 2, 2018
60d1e70
MTH-250 Update filtering, update actions to use new searchQuery obj,…
yuriboyko Aug 6, 2018
e2bf77a
MTH-250 Add sending storeID as a param, update build quire to support…
yuriboyko Aug 7, 2018
9bb79ae
MTH-250 remove using deprecated methods
yuriboyko Aug 7, 2018
53a1ead
MTH-250 Add mutliple types support for result handler
yuriboyko Aug 8, 2018
2849bcd
MTH-250 apply attribute queries to graphql
VladimirPlastovets Aug 8, 2018
600146a
MTH-250 update products response handler
yuriboyko Aug 8, 2018
c88e8eb
Merge branch 'MTH-250' of https://scm2.phoenix-media.eu/scm/mth/vue-s…
yuriboyko Aug 8, 2018
18ed80e
MTH-250 improve handle results for graphql
yuriboyko Aug 8, 2018
a6d6459
MTH-250 remove unused variable
yuriboyko Aug 8, 2018
d8a8865
MTH-250 temporary add checking for attribute type
VladimirPlastovets Aug 9, 2018
a67ecda
MTH-250 update search using dynamic search adapter function
yuriboyko Aug 9, 2018
fe31f69
MTH-250 Fix temporary entity type verification
yuriboyko Aug 9, 2018
df09249
MTH-250 improve using dynamic searchAdapter class
yuriboyko Aug 10, 2018
dc73ea3
MTH-250 add folder and move gql queries to it
VladimirPlastovets Aug 10, 2018
2e8cbe1
MTH-250 apply category queries for graphql
VladimirPlastovets Aug 10, 2018
8a6a169
MTH-250 add nested Field filter support
yuriboyko Aug 13, 2018
aa665a9
MTH-250 Refactoring of product ‘list’ action
yuriboyko Aug 15, 2018
3b01397
MTH-250 quickSearchByQuery function refactoring
yuriboyko Aug 15, 2018
2be9fff
MTH-250 Refactor buildFilterProductsQuery
yuriboyko Aug 15, 2018
6d9207d
MTH-250 added supporting taxrules via graphql
VladimirPlastovets Aug 15, 2018
1599488
Merge branch 'MTH-250' of https://scm2.phoenix-media.eu/scm/mth/vue-s…
VladimirPlastovets Aug 15, 2018
8030929
Merge remote-tracking branch 'origin/master' into MTH-250
yuriboyko Aug 15, 2018
6a1b46d
Merge branch 'MTH-250' of https://scm2.phoenix-media.eu/scm/mth/vue-s…
yuriboyko Aug 15, 2018
a192502
MTH-250 Fix issue with results for empty search string
yuriboyko Aug 16, 2018
c852cc3
MTH-250 remove prepare queries from the frontend templates, fix issue…
yuriboyko Aug 16, 2018
145b0b0
MTH-250 Refactoring of product/list action and quickSearchByQuery fo…
yuriboyko Aug 17, 2018
1606d86
MTH-250 fix problem with range filters
VladimirPlastovets Aug 17, 2018
cd23923
Merge remote-tracking branch 'origin/develop' into MTH-250, fix issue…
yuriboyko Aug 17, 2018
e5ffa33
Merge branch 'MTH-250' of https://scm2.phoenix-media.eu/scm/mth/vue-s…
yuriboyko Aug 17, 2018
e114ce4
Merge remote-tracking branch 'Divante/develop' into MTH-250, fix func…
yuriboyko Aug 17, 2018
c1a4c22
MTH-250 Fix multistore issue
yuriboyko Aug 20, 2018
0ae95be
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 21, 2018
859ba32
MTH-250 cleanup the code
yuriboyko Aug 21, 2018
c52683f
Merge branch 'MTH-250' of https://scm2.phoenix-media.eu/scm/mth/vue-s…
yuriboyko Aug 21, 2018
fc9370f
MTH-250 Fix Inspiration template
yuriboyko Aug 21, 2018
e8fcb11
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 21, 2018
e3a36a9
MTH-250 Update Request #1 - Add backward compatibility for old themes…
yuriboyko Aug 21, 2018
fc89ea7
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 21, 2018
770d6d6
MTH-250 Update Request #2 - move queries to the core/api based on com…
yuriboyko Aug 22, 2018
6a9033a
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 22, 2018
e76813a
Merge remote-tracking branch 'Divante/develop' into MTH-250
yuriboyko Aug 22, 2018
972c085
MTH-250 Merge with updated search lib
yuriboyko Aug 23, 2018
6a4573e
Merge remote-tracking branch 'Divante/develop' into MTH-250
yuriboyko Aug 23, 2018
f98fe2b
Merge branch 'develop' into MTH-250
yuriboyko Aug 27, 2018
7209c19
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 27, 2018
19af951
Merge remote-tracking branch 'origin/develop' into MTH-250
yuriboyko Aug 27, 2018
55321c7
MTH-250 Update new search layer with tier prices
yuriboyko Aug 28, 2018
865276a
Merge branch 'MTH-250' of https://scm2.phoenix-media.eu/scm/mth/vue-s…
yuriboyko Aug 28, 2018
a73eb2d
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 28, 2018
259f8d0
MTH-250 update some queries accordingly to update #1641 by Divante
yuriboyko Aug 28, 2018
59a9906
MTH-250 Update api/queries directory structure
yuriboyko Aug 28, 2018
0de807c
MTH-250 Fix boosts
yuriboyko Aug 28, 2018
81bddaa
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 28, 2018
31a7f38
MTH-250 improve prepare queries, add filter fileds mapping to solve …
yuriboyko Aug 30, 2018
35695a0
Merge remote-tracking branch 'Divante/develop' into MTH-250 + Cleanup…
yuriboyko Aug 30, 2018
20d16f8
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 31, 2018
5a1f5ee
Merge remote-tracking branch 'Divante/develop' into MTH-250
yuriboyko Aug 31, 2018
dafb863
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Aug 31, 2018
a089236
Merge remote-tracking branch 'Divante/develop' into MTH-250
yuriboyko Sep 11, 2018
9a29d2e
Merge remote-tracking branch 'Divante/develop' into MTH-250
yuriboyko Sep 11, 2018
f424551
MTH-250 add min_score for text search
yuriboyko Sep 11, 2018
5c7d832
Merge remote-tracking branch 'MTH/MTH-250' into feature/searchQuery-g…
yuriboyko Sep 11, 2018
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
58 changes: 56 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{
"server": {
"host": "localhost",
"port": 3000
"port": 3000,
"protocol": "http",
"api": "api",
"apiEngine": "elasticsearch"
},
"graphql":{
"host": "localhost",
"port": 8080
},
"elasticsearch": {
"httpAuth": "",
"host": "localhost:8080/api/catalog",
"index": "vue_storefront_catalog",
"min_score": 0.02,
"csrTimeout": 5000,
"ssrTimeout": 1000
},
Expand Down Expand Up @@ -133,6 +141,9 @@
"setupVariantByAttributeCode": true,
"endpoint": "http://localhost:8080/api/product",
"defaultFilters": ["color", "size", "price", "erin_recommends"],
"filterFieldMapping": {
"category.name": "category.name.keyword"
},
"sortByAttributes": {
"Latest": "updated_at",
"Price":"final_price"
Expand Down Expand Up @@ -247,5 +258,48 @@
"endpoint": "http://localhost:8080/api/ext/cms-data/cms{{type}}/{{cmsId}}",
"endpointIdentifier": "http://localhost:8080/api/ext/cms-data/cms{{type}}Identifier/{{cmsIdentifier}}/storeId/{{storeId}}"
},
"usePriceTiers": false
"usePriceTiers": false,
"boost": {
"name": 3,
"category.name": 1,
"short_description": 1,
"description": 1,
"sku": 1,
"configurable_children.sku": 1
},
"query": {
"inspirations": {
"filter": [
{
"key": "category.name",
"value" : { "eq": "Performance Fabrics" }
}
]
},
"newProducts": {
"filter": [
{
"key": "category.name",
"value" : { "eq": "Tees" }
}
]
},
"coolBags": {
"filter": [
{
"key": "category.name",
"value" : { "eq": "Women" }
}
]
},
"bestSellers": {
"filter": [
{
"key": "category.name",
"value" : { "eq": "Tees" }
}
]
}
}

}
38 changes: 38 additions & 0 deletions core/api/product/queries/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import SearchQuery from 'core/store/lib/search/searchQuery'
import config from 'config'

export function prepareQuery ({queryText = '', filters = [], queryConfig = ''}) {
let query = new SearchQuery()
// prepare filters and searchText
if (filters.length === 0 && queryConfig !== '') {
// try get filters from config
if (config.hasOwnProperty('query') && config.query.hasOwnProperty(queryConfig) && config.query[queryConfig].hasOwnProperty('filter')) {
filters = config.query[queryConfig].filter
}
}

if (queryText === '') {
// try to get searchText from config
if (config.hasOwnProperty('query') && config.query.hasOwnProperty(queryConfig) && config.query[queryConfig].hasOwnProperty('searchText')) {
queryText = config.query[queryConfig].searchText
}
}

// Process filters and searchText if exists
if (filters.length > 0) {
filters.forEach(filter => {
query = query.applyFilter({key: filter.key, value: filter.value}) // Tees category
})
}

if (queryText !== '') {
query = query.setSearchText(queryText)
}

// Add basic filters
query = query
.applyFilter({key: 'visibility', value: {'in': [2, 3, 4]}})
.applyFilter({key: 'status', value: {'in': [0, 1]}})

return query
}
18 changes: 18 additions & 0 deletions core/api/product/queries/related.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import SearchQuery from 'core/store/lib/search/searchQuery'
import config from 'config'

export function prepareRelatedQuery (key, sku) {
let relatedProductsQuery = new SearchQuery()

relatedProductsQuery = relatedProductsQuery.applyFilter({key: key, value: {'in': sku}})

relatedProductsQuery = relatedProductsQuery
.applyFilter({key: 'visibility', value: {'in': [2, 3, 4]}})
.applyFilter({key: 'status', value: {'in': [0, 1, 2]}}) // @TODO Check if status 2 (disabled) was set not by occasion here

if (config.products.listOutOfStockProducts === false) {
relatedProductsQuery = relatedProductsQuery.applyFilter({key: 'stock.is_in_stock', value: {'eq': true}})
}

return relatedProductsQuery
}
17 changes: 17 additions & 0 deletions core/api/product/queries/searchPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SearchQuery from 'core/store/lib/search/searchQuery'
import config from 'config'

export function prepareQuickSearchQuery (queryText) {
let searchQuery = new SearchQuery()

searchQuery = searchQuery
.setSearchText(queryText)
.applyFilter({key: 'visibility', value: {'in': [3, 4]}})
.applyFilter({key: 'status', value: {'in': [0, 1]}})/* 2 = disabled, 3 = out of stock */

if (config.products.listOutOfStockProducts === false) {
searchQuery = searchQuery.applyFilter({key: 'stock.is_in_stock', value: {'eq': true}})
}

return searchQuery
}
41 changes: 41 additions & 0 deletions core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,46 @@ import themeModules from 'theme/store'
import themeExtensionEntryPoints from 'theme/extensions'
import extensionEntryPoints from 'src/extensions'

// Declare Apollo graphql client
import ApolloClient from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'
console.log('Add Vue-Apollo graphql client')

const httpLink = new HttpLink({
uri: config.server.protocol + '://' + config.graphql.host + ':' + config.graphql.port + '/graphql'
})

const apolloClient = new ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
connectToDevTools: true
})

let loading = 0

const apolloProvider = new VueApollo({
clients: {
a: apolloClient
},
defaultClient: apolloClient,
defaultOptions: {
// $loadingKey: 'loading',
},
watchLoading (state, mod) {
loading += mod
console.log('Global loading', loading, mod)
},
errorHandler (error) {
console.log('Global error handler')
console.error(error)
}
})

Vue.use(VueApollo)
// End declare Apollo graphql client

store.state.version = '1.3.0'
store.state.__DEMO_MODE__ = (config.demomode === true) ? true : false
store.state.config = config
Expand Down Expand Up @@ -63,6 +103,7 @@ export function createApp (): { app: Vue, router: any, store: any } {
router,
store,
i18n,
provide: apolloProvider.provide(),
render: h => h(App)
})

Expand Down
7 changes: 6 additions & 1 deletion core/build/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
path.resolve(__dirname, extensionsRoot),
path.resolve(__dirname, themesRoot)
],
extensions: ['.js', '.vue', '.ts'],
extensions: ['.js', '.vue', '.gql', '.graphqls', '.ts'],
alias: {
// Main aliases
'config': path.resolve(__dirname, './config.json'),
Expand Down Expand Up @@ -166,6 +166,11 @@ module.exports = {
{
test: /\.(woff|woff2|eot|ttf)(\?.*$|$)/,
loader: 'url-loader?importLoaders=1&limit=10000'
},
{
test: /\.(graphqls|gql)$/,
exclude: /node_modules/,
loader: ['graphql-tag/loader']
}
]
}
Expand Down
77 changes: 36 additions & 41 deletions core/components/blocks/SearchPanel/SearchPanel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import bodybuilder from 'bodybuilder'
import { mapState } from 'vuex'
import i18n from '@vue-storefront/i18n'
import onEscapePress from '@vue-storefront/core/mixins/onEscapePress'
import config from 'config'
import { prepareQuickSearchQuery } from 'core/api/product/queries/searchPanel'

export default {
name: 'SearchPanel',
Expand All @@ -27,49 +26,45 @@ export default {
this.$store.commit('ui/setSearchpanel', false)
},
buildSearchQuery (queryText) {
let query = bodybuilder()
.query('range', 'visibility', { 'gte': 3, 'lte': 4 })
.andQuery('range', 'status', { 'gte': 0, 'lt': 2 }/* 2 = disabled, 4 = out of stock */)
if (config.products.listOutOfStockProducts === false) {
query = query.andQuery('match', 'stock.is_in_stock', true)
}
query = query.andQuery('bool', b => b.orQuery('match_phrase_prefix', 'name', { query: queryText, boost: 3, slop: 2 })
.orQuery('match_phrase', 'category.name', { query: queryText, boost: 1 })
.orQuery('match_phrase', 'short_description', { query: queryText, boost: 1 })
.orQuery('match_phrase', 'description', { query: queryText, boost: 1 })
.orQuery('bool', b => b.orQuery('terms', 'sku', queryText.split('-'))
.orQuery('terms', 'configurable_children.sku', queryText.split('-'))
.orQuery('match_phrase', 'sku', { query: queryText, boost: 1 })
.orQuery('match_phrase', 'configurable_children.sku', { query: queryText, boost: 1 }))
)
return query.build()
let searchQuery = prepareQuickSearchQuery(queryText)
return searchQuery
},
makeSearch () {
let query = this.buildSearchQuery(this.search)
this.start = 0
this.readMore = true
this.$store.dispatch('product/list', { query, start: this.start, size: this.size, updateState: false }).then(resp => {
this.products = resp.items
this.start = this.start + this.size
this.emptyResults = resp.items.length < 1
}).catch((err) => {
console.error(err)
})
if (this.search !== '' && this.search !== undefined) {
let query = this.buildSearchQuery(this.search)
this.start = 0
this.readMore = true
this.$store.dispatch('product/list', { query, start: this.start, size: this.size, updateState: false }).then(resp => {
this.products = resp.items
this.start = this.start + this.size
this.emptyResults = resp.items.length < 1
}).catch((err) => {
console.error(err)
})
} else {
this.products = []
this.emptyResults = 0
}
},
seeMore () {
let query = this.buildSearchQuery(this.search)
this.$store.dispatch('product/list', { query, start: this.start, size: this.size, updateState: false }).then((resp) => {
let page = Math.floor(resp.total / this.size)
let exceeed = resp.total - this.size * page
if (resp.start === resp.total - exceeed) {
this.readMore = false
}
this.products = this.products.concat(resp.items)
this.start = this.start + this.size
this.emptyResults = this.products.length < 1
}).catch((err) => {
console.error(err)
})
if (this.search !== '' && this.search !== undefined) {
let query = this.buildSearchQuery(this.search)
this.$store.dispatch('product/list', { query, start: this.start, size: this.size, updateState: false }).then((resp) => {
let page = Math.floor(resp.total / this.size)
let exceeed = resp.total - this.size * page
if (resp.start === resp.total - exceeed) {
this.readMore = false
}
this.products = this.products.concat(resp.items)
this.start = this.start + this.size
this.emptyResults = this.products.length < 1
}).catch((err) => {
console.error(err)
})
} else {
this.products = []
this.emptyResults = 0
}
}
},
computed: {
Expand Down
4 changes: 2 additions & 2 deletions core/pages/PageNotFound.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import builder from 'bodybuilder'
import { prepareQuery } from 'core/api/product/queries/common'

import i18n from '@vue-storefront/i18n'
import EventBus from '@vue-storefront/core/plugins/event-bus'
Expand All @@ -11,7 +11,7 @@ export default {
asyncData ({ store, route }) { // this is for SSR purposes to prefetch data
return new Promise((resolve, reject) => {
console.log('Entering asyncData for PageNotFound ' + new Date())
let ourBestsellersQuery = builder().query('range', 'visibility', { 'gte': 2, 'lte': 4 }/** Magento visibility in search & categories */).build()
let ourBestsellersQuery = prepareQuery({ queryConfig: 'bestSellers' })
store.dispatch('category/list', {}).then(categories => {
store.dispatch('product/list', {
query: ourBestsellersQuery,
Expand Down
1 change: 1 addition & 0 deletions core/resource/i18n/de-DE.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/resource/i18n/en-US.json

Large diffs are not rendered by default.

Loading