Custom SOLR plugin that returns a field + where you can sort on that field
Hello, *Usercase:* At this moment we have the current situation : We have customers that want to rent houses to visitors of our website. Customers can vary the prices according to specific dates, so renting a house at holidays will cost more. *The problems:* - prices may vary according to the dates a visitor of the website specified. - we want SOLR to calculate this total price based on base_price and the price_%DATE% dynamic fields - we want SOLR to sort the result on this total price - we want SOLR to return this price so we can display it on our website *Example:* house_id : 1 base_price = 20<- base price price_20141225 = 50<- dynamic field with price for a specified date price_20141226 = 60<- dynamic field with price for a specified date house_id : 2 base_price = 30<- base price price_20141229 = 50<- dynamic field with price for a specified date Lets say a customer wants to rent a house from 2014-12-25 till 2014-12-30, the prices would be calculated at query time like this: House 1: 50 + 60 + 20 + 20 + 20 House 2: 30 + 30 + 30 + 30 + 50 *What **i already got:* I did some researche and made my own SearchComponent, which had a few problems: - total price field that got added kept existing unless i removed it or restarted SOLR <- a problem with multiple search queries at the same time - i could not sort on the totalprice field, field seemed to be unknown. *Now my question is:* Do any of you have any suggestions on how to add a total price field (based on base_price and dynamic fields), sort on it and return it to our website during query time?
Re: Custom SOLR plugin that returns a field + where you can sort on that field
well we though of that but there are some problems with a second core for availability: we already have a core containing alot of house information (id, name, latitude, longitude, city , country etc.) which means we would have to do 2 solr queries just to build 1 search result or add alot of double information to the availabillity core (Every availabillity record would also contain id, name, latitude, longitude etc.). I was also reading about joining 2 cores together but the limit on this is that you can not return information from the second core. So of course as second core with availabillity would be a solution it just isn't our preferred one On 04-12-14 14:17, Alexandre Rafalovitch wrote: Have you thought storing 'availability' as a document instead of 'house'. So, the house, date range and price are a single document. Then, you group them, sum them and in post-filter sort them? Some ideas may come from: http://www.slideshare.net/trenaman/personalized-search-on-the-largest-flash-sale-site-in-america (though it is quite old by now) Regards, Alex. Personal: http://www.outerthoughts.com/ and @arafalov Solr resources and newsletter: http://www.solr-start.com/ and @solrstart Solr popularizers community: https://www.linkedin.com/groups?gid=6713853 On 4 December 2014 at 05:54, Mathijs Corten wrote: Hello, *Usercase:* At this moment we have the current situation : We have customers that want to rent houses to visitors of our website. Customers can vary the prices according to specific dates, so renting a house at holidays will cost more. *The problems:* - prices may vary according to the dates a visitor of the website specified. - we want SOLR to calculate this total price based on base_price and the price_%DATE% dynamic fields - we want SOLR to sort the result on this total price - we want SOLR to return this price so we can display it on our website *Example:* house_id : 1 base_price = 20<- base price price_20141225 = 50<- dynamic field with price for a specified date price_20141226 = 60<- dynamic field with price for a specified date house_id : 2 base_price = 30<- base price price_20141229 = 50<- dynamic field with price for a specified date Lets say a customer wants to rent a house from 2014-12-25 till 2014-12-30, the prices would be calculated at query time like this: House 1: 50 + 60 + 20 + 20 + 20 House 2: 30 + 30 + 30 + 30 + 50 *What **i already got:* I did some researche and made my own SearchComponent, which had a few problems: - total price field that got added kept existing unless i removed it or restarted SOLR <- a problem with multiple search queries at the same time - i could not sort on the totalprice field, field seemed to be unknown. *Now my question is:* Do any of you have any suggestions on how to add a total price field (based on base_price and dynamic fields), sort on it and return it to our website during query time?
dynamic field value in ValueSource
Hello, At this moment i'm writing my own SOLR plugin with a custom ValueSourceParser and ValueSource, it's goal is to read a few fields from the document (For now). I'm currently testing with the following fields: multiValued="false" /> stored="true" multiValued="false" /> The problem is, when i try to read the dynamic field with the following code it does not return the correct value (it prints '`', should be 6): public FunctionValues getValues(Map map, final AtomicReaderContext arc) throws IOException { final BinaryDocValues valueDynamic = FieldCache.DEFAULT.getTerms(arc.reader(), "price_discount_1390980_6", false); return new FunctionValues() { @Override public float floatVal(int doc) { final BytesRef dynamic = valueDynamic.get(doc); LOGGER.error(dynamic.utf8ToString()); // prints '`' LOGGER.error(dynamic.toString()); // prints [60 8 0 0 0 6] } } } When i execute the query: price_discount_1390980_6:6, it gives a result so i know the value of the field should be 6. When i try to read a normal field like active or roomids it works fine: public FunctionValues getValues(Map map, final AtomicReaderContext arc) throws IOException { final BinaryDocValues valueActive = FieldCache.DEFAULT.getTerms(arc.reader(), "active", false); final BinaryDocValues valueActive = FieldCache.DEFAULT.getTerms(arc.reader(), "roomids", false); return new FunctionValues() { @Override public float floatVal(int doc) { final BytesRef active = valueActive.get(doc); LOGGER.error(active.utf8ToString()); } } } So my question is: Does anyone know how to get/fix the dynamic field value? would be nice if it would just return 6 :P. Hope to see an answer soon, Mathijs