Skip to content

Instantly share code, notes, and snippets.

@johannessteu
Last active September 9, 2015 17:53
Show Gist options
  • Save johannessteu/4650d891ce87c6180492 to your computer and use it in GitHub Desktop.
Save johannessteu/4650d891ce87c6180492 to your computer and use it in GitHub Desktop.
Productfilter with TypoScript2 and ES
GET /typo3cr-1441789525/Vendor-Foo:Product/_search
{
"query" : {
"terms":
{ "sku": ["2239", "2235", " 2277", "2278", "2276", "2279"]}
},
"facets":
{
"color": {"terms": {"field": "color", "all_terms": false}}
}
}
# Search Products, add a new term line for each filter
GET /typo3cr-1441789525/Vendor-Foo/_search
{
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"must" : [
{"terms" : {"sku": ["2239", "2235", " 2277", "2278"]}},
{"term" : {"__workspace": "live"}}
]
}
}
}
}
}
prototype(Vendor.Foo:FilteredProductList) < prototype(TYPO3.Neos:Content)
prototype(Vendor.Foo:FilteredProductList) {
// Create Facet-Filter
facets = TYPO3.TypoScript:RawArray {
color = TYPO3.TypoScript:RawArray {
terms = TYPO3.TypoScript:RawArray {
field = "color"
}
}
}
// Create SearchFilter for products. Only show products that are configured
searchFilter = TYPO3.TypoScript:RawArray {
sku = ${String.split(q(node).property("products"), ",")}
}
// Add more Filter if set
searchFilter.color = ${request.arguments.color}
[email protected] = ${request.arguments.color != ""}
// Create a query to get filtered products
query = ${Search.query(site).nodeType("RaphaelGmbH.TraumgartenSite:Product").queryFilterMultiple(this.searchFilter, "must").limit(100)}
// Fetch products
products = ${this.query.execute()}
// Note: .facet() is not implemented yet
// you might want to recreate the query and remove the color filter and stuff
filter = ${this.query.facet(this.facets)}
@cache {
mode = 'uncached'
context {
1 = 'node'
2 = 'site'
}
}
}
'RaphaelGmbH.TraumgartenSite:Product':
properties:
sku:
type: string
defaultValue: ''
color:
type: string
defaultValue: ''
ui:
label: 'Farbe'
inspector:
group: 'attr'
position: '20'
search:
elasticSearchMapping:
type: "string"
include_in_all: false
index: 'not_analyzed'
@johannessteu
Copy link
Author

The method .facets() ist not implemented yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment