Creating a custom refinementList component based on two facets - Algolia - algolia

Let’s suppose we have these two facets:
“manufacturer.url”: [“/url1”, “/url2”, “/url3”]
AND
“manufacturer.name”: [“manufacturer1”, “manufacturer2”, “manufacturer3”];
I’d like to create a custom refinmentList component which show all available facets for my hits based on manufacturers.
I used connectRefinementList(MyCustomComponent); and I set manufactuer.url to attribute property.
<CustomManufacturerFilterRefinementList
attribute="manufacturer.url"
currentCategory={currentCategory}
limit={10}
locale={locale}
showMore={showMore}
searchable={searchable}
showMoreLimit={showMoreLimit}
translations={translations}
/>
Now users can see available manufacturers and can filter them or click on them to go to the manufacturer page, but since I fetch the manufacturer.url, I could only able to show the URL in the list, but I’d like to show manufacture’s name in the list and having URL to generate links.
Problem: how can I create a custom refinementList component which fetches data from two facets at the same time and combine them to generate a list of links?
PS: I tried to use searchForFacetValues function inside my custom component to retrvie manufacturer’s name with below query but I couldn’t map each url with name because there is no logical relation between them:
{
"requests": [
{
"indexName": "stg_lots",
"params": {
"facetName": [
"manufacturer.name"
],
"filters": "manufacturer.url:\"froemag\" OR manufacturer.url:\"volvo\" OR manufacturer.url:\"fendt\" ",
"maxFacetHits": 100
}
}
]
}
Thanks

Related

How to get the highest probability records from the collection. (Show most time searched)

I am creating application where it contains many dropdowns(more than 20), user can select any dropdowns to get the results. Every user login they are selecting dropdowns and get the results.
What I am doing is, storing all the selected dropdown values of each user(basically search string), planning to show your common searches, where they can just copy that search string and get the results.
Dropdown selection is mutiple
Intention is reducing the effort of selecting dropdowns if they have most common/almost common search they have. My dataset looks like below data stored in MongoDB.
This data is for single user, likewise it contains for all users.
{
"UserID": "123",
"SearchData": [
{
"searchText": "Area=[Bengaluru,Mumbai] Street_Number=[123,787] Locality=[Hebala,Electronic City] Branch=India",
"searchDateTime": "2020-04-03"
},
{
"searchText": "Area=Delhi Street_Number=[123,797,753,64] Locality=[Rajbhava,Redfort]",
"searchDateTime": "2020-04-04"
},
{
"searchText": "Region=[Asia,Europe] Branch=[India,Germany] Area=Delhi",
"searchDateTime": "2020-04-02"
},
{
"searchText": "Area=[Bengaluru,Mumbai] Team_name=[Team 1, Team 2] IsNewTeam=1 Region=[Asia,Europe] Branch=India",
"searchDateTime": "2020-03-04"
},
{
"searchText": "Region=United_States Branch=NewYork Team=[Team 1,Team 4] Locality=WTO",
"searchDateTime": "2020-04-04"
}
]
}
Expected Results like:
Your most searched/selected fields and Values are(Results for last 150 days searchText), Because I am planning not to keep Old data
1. Area=[Bengaluru,Mumbai] Branch=India Team 1 // Since this is common in many stings(Ex: Here in two strings)
2. Region=[Asia,Europe]
3. Branch=India
4. Team =Team 1
5. Area=[Bengaluru,Mumbai]
6. IsNewTeam == //If any common match found.
7. Area = //If any other common values found Expect the **Bengaluru,Mumbai**
//Ex : Dehli, Noida. This should come here
Any help would be very much appreciated.
Thanks in advance

SAPUI 5 - Aggregated control with two data models

I have a generic tile control that the tile get created base on number of entity available (e.g.: SCARRSet), which is normal. Then in the nested Tile content i need to show the airline logo where the image path is stored in a JSON file. My idea is to use the key in SCARRSet/Carrid to lookup the JSON file to find the image path. So the right image will be displayed for the airline.
Previously i put the image path in Url field which was fine, but that field was meant for something else. Now i want to do it properly.
<l:HorizontalLayout id="hLayout1" allowWrapping="true" content="{flight>/SCARRSet}">
<GenericTile class="sapUiTinyMarginBegin sapUiTinyMarginTop tileLayout"
header="{flight>Carrname}"
subheader="{flight>Carrid}"
press="onTilePressed"
backgroundImage="">
<TileContent unit="{flight>Currcode}" footer="">
<ImageContent src="{flight>Url}" />
</TileContent>
</GenericTile>
</l:HorizontalLayout>
The JSON file looks like following. Is there a way to iterate through each tile to lookup Key = SCARRSet/Carrid then populate imageContent src=(e.g.:"/image/AA.gif")?
{
"icon": [
{
"Key" : "AA",
"Path" : "/image/AA.gif"
},
...
]
}
I would use a formatter function to do the lookup:
src="{formatter: '.formatter.getIconUrl', path: 'flight>Carrid'}"
In the formatter getIconUrl you get the Carrid as input parameter.
For performance reasons I would also suggest to reformat the JSON once to have a hash access to the url: jsonData[carrid] returns the url.

Need to show how much data (In precentage) filled in mongoDb collection

I am using MongoDB for storing data in my application. I need to show the user how much data they filled using percentage.
For example: I have USER collection. In this collection i have several fields. Once the user enter data in their profile. I need to show how much percentage of data they filled in their profile.
In my application. I am using MongoDb and loopback frame work. I didn't defined any property in models.
How to solve this problem.Please help!!
You can add properties in you user model and define percentage against that or you can define one object property like the below mentioned
Suppose you have a User model and in it is settings property, of type object
Settings object will gave 10 keys. 1 keys is 10% then 10 keys filled is
100%. So just check whether user have filled the desired setting and mark a percentage.
so your model will be like
{
"name": "Member",
"base": "User",
"properties": {
"email": {
"type": "string"
},
"settings": {
"type": "object"
}
}
}
and inside your code retrieve the settings object and loop through it to make your percentage
Member.findById(your_id, function(err, usr){
if(!err){
var percentage_completed = 0;
Object.keys(usr.settings).map(function(pro){
if( usr.settings[pro] != "" ){
percentage_completed+=10;
}
})
}
})
I hope this will serve your purpose.

Send more than one term to algolia search

I'm implementing algolia search in my site and i want to get a set of data matching any id's i send to the search, so i need to know how could i send more than one parameter to the search, so i can send a set of ids, something like this:
let client = algoliasearch(APP_ID, API_KEY),
index = client.initIndex(INDEX_NAME);
let term=["3223212","2423434"];
index.search(term, callback)
This is not working right now, have any idea? or even how could i achieve my goal using another algolia feautre like filtering for instance?
If you're trying to retrieve objects by their objectIDs (which you can manually set at creation time to match your database ids), you can simply use the getObjects method.
Extract from the documentation:
You can also retrieve a set of objects:
index.getObjects(['myObj1', 'myObj2'], function(err, content) {
console.log(content);
});
If you're trying to list all the records that belong to a group with a specific id, you can use a facet that will contain this id and filter on it.
Inside your record:
{
"group_id": "3223212",
// or
"group_ids": ["3223212", "2423434"]
}
Inside your index settings:
{
attributesForFaceting: [
'onlyFilter(group_id)'
]
}
At query time:
let ids = ["3223212", "2423434"];
let filters = ids.map(id => `group_id:${id}`).join(' OR ');
index.search('', { filters: filters }, callback);

RESTful master/detail

Having 3 dropdown pickers in a web application. The web application uses a Restful service to populate pickers data.
The two first pickers get their values from something like /years and /colors. The third one should get its values depending on the settings of the two.
So it could be something like /models?year=1&color=red.
The question is, how to make this HATEOAS-compliant (so that the dev does not have to know the way he should create an url to get the models).
The root / gets me a number of links, such as:
{
"_links": {
"colors": "/colors",
"years": "/years",
"models": "???" }
}
What should be instead of ???? If there was some kind of template /models?color={color}&year={year}, the dev would have to create the url. Is this OK?
Or there could be a link to list of years on each color got from /colors and then a link to list of models on each year got from /years?color=red, but i'd have to first choose color, then populate years and then populate models. Any idea if i want to have the model dependent on both color and year, not just the year populated from color?
Is it even possible in this situation to make it hateoas-compliant?
I have not heard of HATEOAS before, but based on what I just read about it, it seems that it supposed to return links to where the consumer of the service can go forward in the "state machine".
In your case that would translate to the links being "function calls". The first two (/colors and /years) are functions that take no parameters (and return "something" at this point), while the third is a function call that takes two parameters: one that is a representation of a color, the other a year. For the first two having a simple URL will suffice for the link, but for the third, you need to include the parameter name/type information as well. Something like:
{
"_links": {
"colors": "/colors",
"years": "/years",
"models": {
"url": "/models",
"param1": {"color"}
"param2": {"year"}
}
}
}
Note: you can use the same layout as "models" for "colors" and "years" as well.
At this point the client knows what the URL to access the functions are and what the parameter (if any) names are to be passed to the function.
One more thing is missing: types. Although you could just use "string", it will not be obvious that the "color" parameter is actually a value from what "/colors" returns. You can be introducing a "type" Color that describes a color (and any functions that operate on a color: give a displayable name, HTML color code, etc.)
The "beefed up" signature becomes:
{
"_links": {
"colors": {
"url": "/colors",
"return": "/type/List?type=/type/Color"
},
"years": {
"url": "/years",
"return": "/type/List?type=/type/Integer"
},
"models": {
"url": "/models",
"param1": {
"name": "color",
"type": "/type/Color"
},
"param2": {
"name": "year",
"type": "/type/Integer"
}
"return": "/type/List?type=/type/Model"
}
}
}
Note: the path "/type" is used just to separate the types from functions, but is not necessary.
This will interchangeably and discoverably describe the functions, what parameters they take, and what values they are returning, so you can use the right value at the right place.
Of course implementing this on the service end will not be easy (especially with parameterized types, like "/type/List" -- think Generics in Java or templates in C++), but this is the most "safe" and "portable" way you can describe your interface to your clients.