0

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.

peter-b
  • 4,073
  • 6
  • 31
  • 43
Ajay Patel
  • 791
  • 11
  • 24
  • 1
    The way `price_per_quant` is designed, I would doubt if it would give you any query options at all. If I were you, I would redesign the schema. Since I don't know all your query requirements, how your other docs look and whether other docs have the same ranges, I have no suggestions to rework it though. – arun Mar 19 '14 at 01:25
  • so you mean for managing price_per_quant we need to create another schema?? am i right – Ajay Patel Mar 20 '14 at 06:18
  • Not another schema. You should rework your existing schema to index that field in another way, maybe as a dynamic field. – arun Mar 20 '14 at 17:09
  • @arun sorry man but we are new in the world of solr. i dont have too much experince in solr. :( – Ajay Patel Mar 21 '14 at 14:06

1 Answers1

1

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

Community
  • 1
  • 1
arun
  • 10,685
  • 6
  • 59
  • 81
  • Hi arun thanks a lot for helping me to solving solr schema building. but my range is not fixed for product for any but your answer give me a good to understand schema very well. this answer may be help some one so i am accepting this answer. again thanks a lot. – Ajay Patel Mar 24 '14 at 06:29