Querying firestore using multiple in clauses - firebase

I'm working on a product listing page (similar to any e-commerce site) where users are expected to filter products based on multiple attributes and multiple values per attribute.
Lets assume data model is as shown below,
Product
Category - Shirt
Size - Medium
Colour - Blue
Dropdown filters on the search page would be,
1. Category: Shirts, T-Shirts, Trousers etc
2. Size: Medium, Large etc
I'm clueless as how to query firestore when user would like to search all Shirts & T-Shirts of Small & Medium sizes?
Query like this isn't supported in firestore,
Firebase.firestore().collection("Products")
.where("Category", "in", ["Shirt, "T-Shirts"])
.where("Size", "in", ["Medium", "Large"])
On top of this, I need to paginate the response so filtering on the client side doesn't seem like an option.
Please suggest if there is any option.

Since you can only have a single in condition in the query, your current approach won't work. The only workaround I know of is to keep a separate field where each value is the combination of sizes that is available. So something like:
"available_in": "Medium_Large"
And then query with:
Firebase.firestore().collection("Products")
.where("Category", "in", ["Shirt, "T-Shirts"])
.where("available_in", "==", "Medium_Large")
This type of solution only works if the number of combinations is reasonable, but that seems to be the case here.

Related

Gremlin Graph Search Query: What Percent of my Workspace has been Filled Out?

I recently began using the Enterprise Architecture tool Ardoq for metadata modeling. I have roughly 55 workspaces set up, all of which have differing numbers of fields and have been filled out to differing degrees.
What I need to do is create a Gremlin query that will tell me what percent of a given workspace has been filled out i.e. count of all custom fields in workspace with data entered / count of total custom fields within the workspace. There are a number of default fields that are automatically filled in, and I would not like to include these. That's what I've tried to do with 'by(properties().not(hasKey('field1','field2',...)' below.
The goal is to create a report for every workspace, then aggregate these reports within a dashboard. So, the ideal query will have minimal inputs that need to be changed when calculating this percentage for separate workspaces. I believe that the only input that should need to be changed is the workspace ID, and that is what I have tried in my query below. However, while the query below was accurate for 1 of my workspaces, it is anywhere from 10% to 50% off for all others. Any suggestions?
My Query:
totalFieldCount = g.V().
group().
by('typeId').
by(properties().not(hasKey('_id','Ardoq-ID','last-updated-date','last-updated-by','parent','lastModifiedByName','createdByEmail','type','name','created','rootWorkspace','typeId','created-by','created-date','last-modified-by','lastUpdated','lastModifiedByEmail',
'component-key','entity-type','createdByName','model','description','_order','children','incomingReferenceCount','outgoingReferenceCount','persistent','_version','ardoq','icon','version','target','origin','image','shape','id','order','targetWorkspace','isPublic','returnValue','displayText','source','ardoq-entity-type','color','mustBeSaved','tags','lock')).label().dedup().count()).next()
g.V().has('rootWorkspace', '3907706fb235eda5ec15fb89').
project('fieldsOnThisComponent', 'allFields').
by(properties().not(hasKey('_id','Ardoq-ID','last-updated-date','last-updated-by','parent','lastModifiedByName','createdByEmail','type','name','created','rootWorkspace','typeId','created-by','created-date','last-modified-by','lastUpdated','lastModifiedByEmail','component-key','entity-type','createdByName','model','description','_order','children','incomingReferenceCount','outgoingReferenceCount','persistent','_version','ardoq','icon','version','target','origin','image','shape','id','order','targetWorkspace','isPublic','returnValue','displayText','source','ardoq-entity-type','color','mustBeSaved','tags','lock')).count()).
by(map{ totalFieldCount[it.get().value('typeId')] }).
math('100 * fieldsOnThisComponent / allFields').
mean().
map{ it.get().round(2) }

Different results with and without ga:pagePath dimension

I use the following query parameters in Google Analytics:
start-date=2017-10-01
end-date=2017-10-01
metrics=ga:users
When I filter by ga:pagePath==/charity/ the result is 100.
When I filter by ga:pagePath=~/charity/ the result is 139.
When I filter by ga:pagePath=~/charity/;ga:pagePath!=/charity/ The result for some reason is 71. How is it possible?
Moreover, if I add the ga:pagePath dimension when I filter by ga:pagePath=~/charity/ I can see that the results add up to way more than 139. In fact, it shows that users for /charity is 100 and the rest of URLs add up to 137 (counted them manually). Could someone, please, help me to understand what am I missing here?
I wager that at least part of the problem is that you query a user scope metric and filter by a hit based dimension.
A user can see multiple pages that contain "charity" in the url, so the total from all pages is more than total users, e.g, if one user has seen page /charity/a and page charity/b the rows would add to two users, but the absolute total is just the single person.

What is a valid format for params in news bing url?

I'm trying to add some filters to request for news in bing api but currently I don't get any effects of doing this ( for example filter for news from current month).
I'm trying to this with : https://api.cognitive.microsoft.com/bing/v5.0/news/search?freshness=month&?category=business , and replacing some filters here but I always getting the same result.
Currently i want to add three filters : freshness, category and language for news from current day and month.
So it is bug or I'm doing something wrong with filters ?
One problem is that you have an extra "?" in your query. You only need the first one, and then you can use "&" to delimit individual parameters:
https://api.cognitive.microsoft.com/bing/v5.0/news/search?freshness=month&category=business
You might also try adding a market to the query string, like so:
https://api.cognitive.microsoft.com/bing/v5.0/news/search?freshness=month&category=business&mkt=en-us
I'm using 7.0 and don't know what headers you're passing, so I can't test this directly, but it's possible a default market isn't being set. Since categories are market specific, then depending on how Bing handles this, it could plausibly prevent your category from being used.

NEO4J - Recursive query aggregation

I have the following query
MATCH (category:Category {id:'qwe'} )
MATCH (category)-[:CHILD_OF*0..50]->(subcats:Category)<-[:PHOTO_OF]-(photo:Photo)
return (subcats.name), count(photo)
This query returns only the photo counts of the exact categories that photos belong to, i want aggregated count of categories photos including the photos of the child categories, i guess this used to work but broken after 2.3.x update.
Try this query:
MATCH (category:Category {id:'qwe'} )
MATCH (category)-[:CHILD_OF*0..50]->(subcats:Category)<-[:PHOTO_OF]-(photo:Photo)
WITH category.name AS cat, collect(subcats.name) AS subcats, count(photo) AS num
RETURN cat, subcats, num
Is that the behavior you are trying to achieve?
I'm not sure what might have changed between 2.2.x and 2.3 with your query. Would you be willing to share your data so we can try to reproduce?

Drupal 7 Views Expose Filter Price Range as Checkboxes

I am using Drupal 7 to build a product reviews site. The product reviews search page is built with Views 3 and Better Exposed Filters. I need an exposed filter for a price field that consists of price ranges as checkboxes. I have set up a grouped exposed filter for price with the proper ranges, made the filter allow multiple selections and then implemented hook_form_alter to set the filter to be themed with BEF checkboxes. The only problem now is the filter's where clause is searching for the ranges with an AND clause instead of an OR. So, I would like the user to select multiple price ranges and the results include products within either price range but instead the search is looking for product that are in both ranges, resulting in no products.
I have attempted to use hook_views_query_alter, but can not output so much as a dsm('test'). I think this may be because the view uses autosubmit.
Does anyone know how I can get this filter to work properly?
As the Advanced documentation of the Filter section says:
When using grouped filters with the option: 'Enable to allow users to select multiple items' checked, you probably may want to to place the filter in a separated group and define the operator of the group as 'OR'. This may be neccesary because in order to use multiple times the same filter, all options have to be applied using the OR operator, if not, probably you will get nothing listed since usually items in a group are mutually exclusive.
Therefore, you may want to create a new group (going to the 'reorder tab') and set the operator to OR. Then, just move the exposed filter inside that group.

Resources