Grouping with Filter Query Solr - solr

I had document in solr as mentioned below
Document 1
{
"event_name":"product viewed",
"event_property":["category","product_name","product_code","price","brand","color","discount","is_new_visitor"],
"event_value":["category-sunglasses","product_name-david blake grey sunglasses","product_code-lcsgdb364x1880gryx""price-590","brand-david blake","color-grey","discount-70"],
"session_id":"mf1545212054754888840",
"company_id":"31",
"created":1545212153,
"email":"zzzz#gmail.com",
"name":"zzzz"
}
Document 2
{
"event_name":"add to cart",
"event_property":["category","product_name","product_code","price","brand","color","discount","is_new_visitor"],
"event_value":["category-sunglasses","product_name-david blake grey sunglasses","product_code-lcsgdb364x1880gryx""price-590","brand-david blake","color-grey","discount-70"],
"session_id":"mf1545212054754888840",
"company_id":"31",
"created":1545212153,
"email":"zzzz#gmail.com",
"name":"zzzzz"
}
Document 3
{
"event_name":"product viewed",
"event_property":["category","product_name","product_code","price","brand","color","discount","is_new_visitor"],
"event_value":["category-sunglasses","product_name-david blake grey sunglasses","product_code-lcsgdb364x1880gryx""price-590","brand-david blake","color-grey","discount-70"],
"session_id":"mf1545212054754888841",
"company_id":"31",
"created":1545212153,
"email":"yyyy#gmail.com",
"name":"xxxxxx"
}
document have email and activity perform by user in event key.now i need to make request to group email to find unique email using filter query.i have used the query mentioned below
http://solr-url/solr/solr-core/select?q=*:*&fq=((event_name:"product+viewed"
+AND+event_property:"product_name"+AND+event_value:"category-sunglasses")+AND+(event_name:"add+to+cart"+AND+event_property:"product_name"+AND+event_value:"category-sunglasses"))&group.limit=1&group.ngroups=true&group=true&group.field=email
In response i am not getting the email e.g user who as performed both event e.g "product viewed" and "add to cart".

Just check your query, the filter query should AND, should be OR.
fq=((event_name:"product+viewed"
+AND+event_property:"product_name"+AND+event_value:"category-sunglasses")+OR+(event_name:"add+to+cart"+AND+event_property:"product_name"+AND+event_value:"category-sunglasses"))

Related

firestore data model using multiple sub collections

I have a current structure in my firestore.
Data model:
- users (collection)
- 9d5UCo4RtyTosiFAIvnPK4zFCUk1 ( each user is a separate document )
- trips ( collection )
- New York (Document)
- fields: date, description, photos:[url1, url2, ....] ( fields in the New York document), status:public
- Los Angeles
....
Now I want to add notes, likes and metadata for each photo in the New York, LA, etc photos array.
I have a few ideas but not sure which is scalable and works well for what I want to do with notes, likes and metadata.
The notes don't have to load at the same time the photos do. The user would click to open notes which could be a new query to DB. But each photo does need to know how many notes are associated with each photo when photos are been displayed.
Solution 1:
photos array would be an object instead.
const photos = {
isdffd: {
url: "path",
likes: 100,
metadata: {
...
},
},
xxydfsd: {
url: `path`,
likes: 10,
metadata: {
...
}
},
};
Then I have a collection of notes back up where trips is and use the photo id as the id for the note. but that limits me to 1 note per photo which I want to be able to add multiple notes.
I also want to be able to build a search page which would search through all notes throughout all trips and display them grouped by trip in the results.
What would be a good approach for this kind of setup with what I have right now which is using sub-collections for most of my structure so far.
Solution 2:
add another sub-collection inside each trip document called photos
each photo would be its own document with likes, metadata and notes. But then notes needs to be a sub-collection of each photo document. This would make it hard to search all trips and all notes for each photo.
The way your original function has been structured:
- users (collection)
- 9d5UCo4RtyTosiFAIvnPK4zFCUk1 ( each user is a separate document )
- trips ( collection )
- New York (Document)
- fields: date, description, photos:[url1, url2, ....] ( fields in the New York document), status:public
- Los Angeles
....
If you implement the first solution, you will limit your code if in the future you want to add another field to the photos object, or as you add additional photos to the object.
Adding a photos sub-collection inside your trips is your best option, this way your collection can grow and avoid the limitation of the first solution (having to make any change manually). If your notes are only text, then you can keep them inside each photo document as an array, avoiding another subcollection. Keeping the photos as a sub-collection and keeping the URL, likes, metadata and notes (if they are only text) inside each photo created should not add much difficulty when querying.

Should I save this in the same user collection or create another collection?

I am creating this project with reactjs and firebase firestore where users can register and log in to this website. The user has a QR code to be scanned by the admin and retrieves information
I'm not sure if I should create another collection when the admin submits the entered vaccination status of the user or should I just still save it in the users collection.
I'm asking this because I will be creating a monthly graph for each of the vaccines for those who were at least at 1 dose or fully vaccinated. Will this be fine if I'll just save it in the firestore by creating another collection or just save it in the users collections?
If each user can have at most 2 doses, you can simply store the data as a map in user's document.
{
firstName: "name",
...otherFields,
doses: {
1: {
...dose1Info
},
2: {
...dose2Info
}
}
}
You can then use dot notation to query using those nested field like this:
const query = colRef.where("doses.1.type", "==", "AstraZeneca")
This query will return documents of users whose first does was AstraZeneca. Similarly you can query based on other dose info fields.
While #Dharmaraj answer will work, you can also consider an alternative solution that looks like this:
Firestore-root
|
--- users (collection)
|
--- $uid (document)
|
--- vaccinType: "AstraZeneca"
|
--- doseOne: true
|
--- doseTwo: true
To find all users that are vaccinated with "AstraZeneca", you can use the following query:
const query = usersRef.where("vaccinType", "==", "AstraZeneca")
To find all users that are vaccinated with "AstraZeneca" and got the first dose simply use:
const query = usersRef.where("vaccinType", "==", "AstraZeneca")
.where("doseOne", "==", true)
To find all users that are vaccinated with "AstraZeneca" and got the first and the second dose you can use:
const query = usersRef.where("vaccinType", "==", "AstraZeneca")
.where("doseOne", "==", true)
.where("doseTwo", "==", true)
If you need additional data the doses, you can create two separate fields for that.

How to show facet values on the front end in Hybris?

I have added a brand attribute of String type in the ProductModel through item.xml.
I need to create a facet for brand. I have two brands - Sony and Canon.
After creating the facet, I'm able to see "Shop by Brand" on the UI, but I'm not able to find Sony or Canon under it.
The impexes I used are:
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier) [unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];facet[default=true];facetType(code);facetSort(code);priority;visible;useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;valueProviderParameter;facetDisplayNameProvider;customFacetSortProvider;topValuesProvider;rangeSets(name)
;$solrIndexedType;brand;string;;;;;;Refine;Alpha;;true;true;true;springELValueProvider;
INSERT_UPDATE SolrSearchQueryProperty; indexedProperty(name, solrIndexedType(identifier))[unique = true]; searchQueryTemplate(name, indexedType(identifier))[unique = true][default = DEFAULT:$solrIndexedType]; facet[default = true]; facetType(code); includeInResponse[default = true]; facetDisplayNameProvider;facetSortProvider;facetTopValuesProvider
; brand:$solrIndexedType ; ; ; ; ;
Can someone please point out what am I missing?
To make brand attribute as to available as facet need to follow below steps:
Index brand attribute to SOLR via value provider by creating
SolrIndexedProperty and associating it with value provider
After indexing ensure that data being sent to SOLR for corresposding products
Next steps is to do facet settings in Bakcoffice (or this can also be done via solr.impex while creating SolrIndexedProperty header impex for custom brand attribute)
Edit that attribute in Backoffice facet configuration and go to "Facet Settings" tab which will enable us to define facet for custom (brand) attribute, which can be used to filter results based on facet value in PLP or SLP. Make "Facet" to 'TRUE'
Or this can be handle via impex by setting facet[default=true]
Select facet type to be 'Single Select' or 'Multi Select' via facetType(code)
Re-Index Solr and changes should get reflect upon Search or PLP

Microsoft Graph Member of limit

Microsoft Graph API is not returning more than 100 object
I tried below query to get "memberof" details of a particular user. However it return only first 100 objects. However User is member of 210 groups. Could you please help me with correct query
https://graph.microsoft.com/v1.0/users/mytestuser#domain.com/memberOf
GET https://graph.microsoft.com/v1.0/users/mytestuser#domain.com/memberOf
The response should contain a "#odata.nextLink" field which can be used to retrieve the next page of the result. An example response could be:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/users/mytestuser#domain.com/memberOf?$top=5&$skiptoken=X%2744537074090001000000000000000014000000B2B64E48AF94EB439F56F5A33CB75C9301000000000000000000000000000017312E322E3834302E3131333535362E312E342E32333331020000000000011C7FEE5EFEFA46459248691C529273D3%27",
"value": [
{ ... }
...
]
}
To retrieve all results we should keep following "#odata.nextLink" of each responses until the response does not contain a "#odata.nextLink" field.
Please have a look at this doc explaining how paging works in Microsoft Graph: https://learn.microsoft.com/graph/paging
It works the same with the /memberOf API
You can use query parameters to customize responses - like so for example get the top 300 - this will return til 300 groups etc
https://graph.microsoft.com/v1.0/users/mytestuser#domain.com/memberOf?$top=300
This is a quick and dirty way, since the memberOf method does not support all OData Query Parameters
https://learn.microsoft.com/en-us/graph/query-parameters

How do you fetch all documents (including non-existent ancestor documents) in a Firebase collection?

I am trying to pull all the documents in the collection 'users', but it only pulls 'fred' and 'lisa', and ignores all the italicized documents:
For this data:
Trying to get all documents:
Will yield:
info: length 2
info: fred => { gender: 'male', contacts: [ '' ] }
lisa => { contacts: [ '' ] }
According to the Firebase documentation (Firebase: Add and Manage Data):
Warning: Even though non-existent ancestor documents appear in the console, they do not appear in queries and snapshots. You must create the document to include it in query results.
Note: The non-existent ancestor users seem to be auto-created when the user hits the sign-up button that triggers a firebase.auth() function (fred and lisa were created manually).
How would I print the contacts of each user if some of the users do not show up in my queries? Would I need to periodically run a script that manually re-adds all the users or is there a more elegant solution?
As you have mentioned, these "documents" are displayed with an italic font in the Firebase console: this is because these documents are only present (in the console) as "container" of one or more sub-collection but they are not "genuine" documents.
As matter of fact, if you create a document directly under a col1 collection with the full path doc1/subCol1/subDoc1, no intermediate documents will be created (i.e. no doc1 document).
The Firebase console shows this kind of "container" (or "placeholder") in italics in order to "materialize" the hierarchy and allow you to navigate to the subDoc1 document but doc1 document doesn't exist in the Firestore database.
Let's take an example: Imagine a doc1 document under the col1 collection
col1/doc1/
and another one subDoc1 under the subCol1 (sub-)collection
col1/doc1/subCol1/subDoc1
Actually, from a technical perspective, they are not at all relating to each other. They just share a part of their path but nothing else. One side effect of this is that if you delete a document, its sub-collection(s) still exist.
So, if you want to be able to query for these parent documents, you will have to create them yourself, as jackz314 mentioned in the comments.
If you're trying to list all your registered users from Firebase auth, you can use the Firebase SDK function:
function listAllUsers(nextPageToken) {
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult){
listUsersResult.users.forEach(function(userRecord) {
console.log('user', userRecord.toJSON());
})
if (listUsersResult.pageToken) {
// list next batch of users
}
})
.catch(function(err) {
console.log('Error listing users: ', error)
});
}
listAllUsers();
via http://firebase.google.com/docs/auth/admin/manage-users#list_all_users

Resources