I have two models Review and Product. Product has many reviews.
Is there a gem with which I can sort reviews belonging to a product? So far I am using mongoid-orderable to sort reviews. But it doesn't have the ability to sort all the reviews of a product.
Thank you!
Is Review an embedded document?
You can sort your reviews during the query using #sort based on a field order of the collection Review or any other field, like created_at for example.
my_product.reviews.order_by(:created_at)
Related
I have a multitenant site, whose products are indexed in Solr, so visitors can search by product name, or any other product property.
Now, I would like to filter by product price.
There are two problems:
Not all tentants have the same products on their website.
The product price can differ from one customer to another, as each tenant can change the price of each of the product it uses.
So given a tenantId, I'd like to search for all products that tenant has, which are in a given price range.
I don't think I can store a Map<CustomerId, Price> for each product and somehow query that, so I'm a bit stuck on how to design the schema. At the moment, I just have, for each product, a multivalued property called customer, so I can just filter by all products of a given tentant.
Any help appreciated, thanks!
I have a document in a lucene which, say, models a shop.
The document has a number of terms which specify the items the shop has. Now I want to associate a price with every item in the document without having to create extra fields for each item. I want to be able to sort on these prices and filter on these prices.
How can I achieve this functionality? I had thought of payloads for sorting, but not sure how to do the filtering part?
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.
I have a model - "Category" which HABTM "Blog". I need to create a query that will only select categories that have more zero blogs associated with them. I'm having trouble working out how to do this. All I've come up with is getting the categories out of the database using find('all'...) and then extracting those that have something in the $category['Blog'] array. Obviously I'd much prefer to not have to ask the database to do all that work, so a more elegant solution would be much appreciated.
Thanks for reading!
not really elegant (short), but I think this is the correct way:
add a blogs_category_count field to categories table
add Category hasMany BLogsCategory with counterCache
so you just have to add a condition to that find('all')
I have a model Content which belongsTo Categories, hasMany Publishers, and Publisher belongsTo city.
There is also a search form where someone selects from a drop-down box which category to view and which city.
But how can I combine these two in a single paginate condition? I mean I cannot do something like:
$this->paginate('Content',array('conditions' =>array('Category.id'=>$category,
'City.id'=>$city)));
because to get cities cake performs a different query.
Nor can I do something like:
$this->paginate('Content',array('conditions' =>array('Category.id'=>$category),
'contain'=>array('Publisher.City'=>array('conditions'=>array(City.id'=>$city)))));
because this will search according to category and filter the city results according to $city.
I know I can do something like:
$this->Content->Publisher->City->find(...)
but this will change the output of my paginated data.
What I usually do is write my custom query where I LEFT join all models and filter the results in WHERE. But I wanted to aks if there is a more cake (sic) way!
thanks
i've experienced the same thing when i first try to create a simple search engine with hasmany relationship.
i used multiple $this->find() and assigned it in a variable then on the paginate code i used$this->paginate(array_merge(name of the variables used in $this->find()));.
hope this will help you...
~gio