[英]Complex query for searching in solr
We are storing data for product entity in below format in solr search engine. 我们在Solr搜索引擎中以以下格式存储产品实体的数据。
{
id:unique_id,
...
...
...
price_per_quant: [
"1-50|1",/* here price per quantity is save in key value pari e.g for quantity 1 to 50 price should be 1*/
"51-100|2",
"101-150|3",
"151-200|4"
]
}
Case I need to follow 案例我需要遵循
And one more thing: how can I manage the facet search on those price_per_quant field? 还有一件事:如何在这些price_per_quant字段上管理方面搜索?
I am using Solarium-project php library for connecting with solr. 我正在使用Solarium-project php库与solr连接。
Here is one possible way to rework your schema. 这是重做模式的一种可能方法。 Hope this gives you some idea.
希望这能给您一些想法。
I am going to assume that the prices per quantity is in multiples of 50 below for all your products. 我将假设您所有产品的每数量价格都低于50。 Else you will need to reduce your intervals.
否则,您将需要缩短间隔时间。
Define a dynamic field called price_upto_*
like this: 定义一个名为
price_upto_*
的动态字段,如下所示:
<dynamicField name="price_upto_*" type="integer" indexed="true" stored="true"/>
Then you can index your docs with fields like this: 然后,您可以使用以下字段将文档编入索引:
price_upto_50: 1,
price_upto_100: 2,
price_upto_150: 3,
price_upto_200: 4
Here is how you will write your client code for the queries. 这是您将如何为查询编写客户端代码的方法。 Below use integer division (meaning (20/50) = 0, (60/50) = 1, etc.,)
下面使用整数除法(意思是(20/50)= 0,(60/50)= 1,等等,)
Query: if i search for quantity 20, then above result should display. 查询:如果我搜索数量20,则应显示以上结果。
In your client, you need to do calculate: 50 * (1 + (20/50)) = 50 * (1 + 0) = 50. So the field you are searching for is price_upto_50
. 在您的客户中,您需要进行计算:50 *(1 +(20/50))= 50 *(1 + 0)=50。因此,您要搜索的字段是
price_upto_50
。 Your query will be like q=price_upto_50:[* TO *]
. 您的查询将类似于
q=price_upto_50:[* TO *]
。
Query: if i search for price 1, then above result should display. 查询:如果我搜索价格1,则应显示以上结果。
q=price_upto_50:1 OR price_upto_100:1 OR price_upto_150:1 OR price_upto_200:1
As you can see, this can become ugly if you have prices for every interval of 50. So you can use a copy field as suggested here and copy all your price fields into that one field and issue a search like: 如您所见,如果每隔50个时间都有价格,这将变得很丑陋。因此,您可以按照此处的建议使用一个复制字段,然后将所有价格字段复制到该字段中,然后执行以下搜索:
q=price_upto_static:1
Query: if i search for price 3 and quantity 60 then above result should not display. 查询:如果我搜索价格3和数量60,则不应显示以上结果。
q=price_upto_100:3
(Your doc won't match.) (您的文档将不匹配。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.