0

I am having a list of products. I have added to the google appengine search API index with each product being each document. User can search for products. So far everything is good.

Now I want the user to be able to sort by price of the product ascending or descending. If i have fixed price for each product, I could simply build separate indexes and put the documents inside them. But unfortunately, the prices are dynamic. The product price can change 3-4 times a day. I have more than 200,000 products.

Since rewriting the document each time the price changes is bad, I have a ndb datastore model which has the documentID and price as the entity attributes.

Is there any way to sort the search api results, based on the price in the ndb model. Alternate design solutions are also welcome.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Sriram
  • 8,574
  • 4
  • 21
  • 30
  • Why are you making the assumption that updating the document is a bad practice? If the document is "related" to an ndb model why wouldn't you want to update it every time? – Jesse Aug 16 '15 at 17:06
  • @Jesse since search documents are immutable, every time i need to modify the price, i need to overwrite the entire document which will cause the document to be re-indexed. So it will effect me in terms of indexing costs too. – Sriram Aug 16 '15 at 18:07
  • The only strategy I see is to sort after the fact in python. I would still get it to sort based on the old price, as things like timsort will work faster if it already fairly well sorted. – Tim Hoffman Aug 17 '15 at 10:44
  • @TimHoffman if my understanding is correct, the search api returns by default in the order in which the documents were inserted. Since I do not have the price in the document, there is a big chance that the first N products will not contain the lowest price product. Is there any way to tie the search document to the ndb entity – Sriram Aug 17 '15 at 11:14
  • There are ranking/sorting options - https://cloud.google.com/appengine/training/fts_adv/lesson2?hl=en – Tim Hoffman Aug 17 '15 at 12:42

0 Answers0