Question

We are storing data for product entity in below format in solr search engine.

{

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

  • if I search for quantity 20 then above result should display.
  • if I search for price 1 then above result should display.
  • if I search for price 3 and quantity 60 then above result should not display.

And one more thing: how can I manage the facet search on those price_per_quant field?

I am using Solarium-project php library for connecting with solr.

Was it helpful?

Solution

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. Else you will need to reduce your intervals.

Define a dynamic field called price_upto_* like this:

<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.,)

Query: if i search for quantity 20, then above result should display.

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. Your query will be like q=price_upto_50:[* TO *].

Query: if i search for price 1, then above result should display.

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:

q=price_upto_static:1

Query: if i search for price 3 and quantity 60 then above result should not display.

q=price_upto_100:3

(Your doc won't match.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top