我用过elasticsearch-dsl==5.2.0,elasticsearch==5.3.0和Django==1.8.15。
Django模型:
class Item(models.Model):
price = models.DecimalField(default=0)
def to_search(self):
return DocItem(
meta={'id': self.id},
price=self.price
)
Run Code Online (Sandbox Code Playgroud)
DocType类:
class DocItem(DocType):
price = Integer()
Run Code Online (Sandbox Code Playgroud)
FacetedSearch类:
class ItemSearch(FacetedSearch):
index = 'item'
doc_types = [DocItem, ]
fields = ['price']
Run Code Online (Sandbox Code Playgroud)
当我需要使用搜索所有项目时price == 5.0,执行下一个操作:
search = ItemSearch().search()
result = search.filter('match', price=5.0).execute()
Run Code Online (Sandbox Code Playgroud)
问题:
如何搜索价格范围为1.0 <价格<= 5.0的所有项目?
我想构建 URL 模式,如下所示[lang]/category/[name]-[suffix],其中:
suffix是几个字符串之一,例如:['super-product', 'great-gadget', 'ta-ta-ta']name是一个多词slug,比如a-bb-ccc为了实现它,我决定使用Matching:
export function match(param) {
let result = /^(super-product|great-gadget|ta-ta-ta)/.test(param);
return a;
}
Run Code Online (Sandbox Code Playgroud)
对于 URL 来说/en/category/a-bb-ccc-super-product/,param是bb-ccc-super-product。问:如何让 Svelte 将 URL 拆分为所有可能的选项中的 slugs,例如:a+ bb-ccc-super-product、a-bb+ ccc-super-product、 ...、a-bb-ccc-super+ product,而不仅仅是一个a+bb-ccc-super-product?
另外,我尝试使用处理程序来解决此问题,但失败了,因为我无法更改 URL。