Displaying a 'Top Result' with Algolia? - algolia

I want to search 3 different indices at once, breaking out their results into 3 separate sections.
Above these 3 sections though, I want to display a 4th section with a single result row, and this section will be titled "Best Result".
It should take the best result of the 3 indices that most perfectly matches.
Does anyone know how I can achieve this? Thanks!

By design, when the ranking of each index is properly set (both attributeToIndex, and customRanking settings filled), the Algolia engine returns the most relevant et popular results for each new search request. First the one without typos and with perfect matches, then the others...
Which mean that if you want to display all the top results on a single page, you only need to take the N first result of each index.
Then it's just a matter of display. Like on the following websites, you can imagine to display those results into multiple columns:
http://telly.com/
Prototype built using the TED API
Feel free to look at tips about the best way to display result hits in multiple columns using Algolia and Bootstrap 3
Beside that you can also consider passing the getRankingInfo=1 parameter with your search query, and filter the results displayed accordingly to the matching info returned for each hit within the _rankingInfo property.
firstMatchedWord: 2000
geoDistance: 0
geoPrecision: 1
nbExactWords: 2
nbTypos: 0
proximityDistance: 1
userScore: 9499
words: 2

Related

Magento 2.4 collection filtering no longer working - strange paging issue

I'll start by saying that this worked correctly prior to Magento 2.4.
using $collection->addAttributeToFilter("sku",'21V12') does seem to filter the products, but it does so very strangely. if i have 20 products in a category and i use that filter, there are 2 different scenarios
The results are correct and it shows 1 of 1
The results show "We can't find products matching the selection."
the difference is that if the sku i'm filtering on is on page 1, then i get the first results, but if the sku is on a different page, i get the "We can't find products matching the selection."
If I add the page to the url, I get the result (adding p=2 or p=3 for example)
Any idea why that is? I've tried this in multiple points in the code to no avail.
That filtering on sku is a simple example, but lets say we want to do a more involved filter like
$collection->addAttributeToFilter("special_name",'some_custom_text')
and that gives 20 results, sometimes there are none on page 1 and 3 on page 2, etc.
Anyway, it seems to just be hiding items in the display and not actually giving the results we are looking for.
I've tested this on a baseline 2.4.2 install with the Luma theme.
To verify, the easiest way, add this at line 147 in vendor/magento/module-catalog/Model/Layer.php
$collection->addAttributeToFilter("sku",'21V12');
Substitute a sku you have on page 2 of a category page. you should get the "We can't find products matching the selection." page, but if you add ?p=2 (or whatever page your item is on normally) you'll get that product as a result.

Is is possible limit the number of rows in the output of a Dataprep flow?

I'm using Dataprep on GCP to wrangle a large file with a billion rows. I would like to limit the number of rows in the output of the flow, as I am prototyping a Machine Learning model.
Let's say I would like to keep one million rows out of the original billion. Is this possible to do this with Dataprep? I have reviewed the documentation of sampling, but that only applies to the input of the Transformer tool and not the outcome of the process.
You can do this, but it does take a bit of extra work in your Recipe--set up a formula in a new column using something like RANDBETWEEN to give you a random integer output between 1 and 1,000 (in this million-to-billion case). From there, you can filter rows based on whatever random integer between 1 and 1,000 as what you'll keep, and then your output will only have your randomized subset. Just have your last part of the recipe remove this temporary column.
So indeed there are 2 approaches to this.
As Courtney Grimes said, you can use one of the 2 functions that create random-number out of a range.
randbetween :
rand :
These methods can be used to slice an "even" portion of your data. As suggested, a randbetween(1,1000) , then pick 1<x<1000 to filter, because it's 1\1000 of data (million out of a billion).
Alternatively, if you just want to have million records in your output, but either
Don't want to rely on the knowledge of the size of the entire table
just want the first million rows, agnostic to how many rows there are -
You can just use 2 of these 3 row filtering methods: (top rows\ range)
P.S
By understanding the $sourcerownumber metadata parameter (can read in-product documentation), you can filter\keep a portion of the data (as per the first scenario) in 1 step (AKA without creating an additional column.
BTW, an easy way of "discovery" of how-to's in Trifacta would be to just type what you're looking for in the "search-transtormation" pane (accessed via ctrl-k). By searching "filter", you'll get most of the relevant options for your problem.
Cheers!

QUERY which outputs a hyperlink to a cell in another tab in the same sheet

In Google Sheets, I'm trying to write a QUERY which outputs a column displaying a hyperlink which links you to the cell pulled in by the QUERY, in another tab on the same sheet.
Example (all within the same Sheet):
Tab 1:
**Name**
Chandler
Ross
Joey
Utilizing the hyperlink() function as I read from this question, I've been able to link to another tab within the same sheet by hardcoding the hyperlink formula. But how can you incorporate this within a QUERY?
Tab 2: (my attempt but errors out)
=QUERY(Sheet1!A:A,"SELECT hyperlink("#gid=123456789range=A2", A2)")
Desired Output:
**Name**
Chandler [hyperlinked to cell A2]
Ross [hyperlinked to cell A3]
Joey [hyperlinked to cell A4]
I am going to give the answer in more general terms than you asked for, so that it is (hopefully) more useful to others.
You can do this by turning your attempt inside out. That is, use QUERY to pull the data, input it into HYPERLINK, and then use ARRAYFORMULA to do this for the whole list. Since you need the matched pairs of the names and the corresponding URLs, QUERY will be used twice with the same filter condition.
For example, if you had the table:
**Table A1:C4**
Name, URL, Rating
SE,https://stackexchange.com, 2
Physics SE,https://physics.stackexchange.com, 4
Maths SE,https://math.stackexchange.com, 5
and you wanted to list all the URLs where the rating was greater than 3, labelled by the corresponding name in column A, then you could use:
=arrayformula(hyperlink(query(A2:C4,"select B where C>3,0),query(A2:C4,"select A where C>3",0)))
This will output a column containing two links:
SE
Maths SE

Tableau Mixed Data

I've been tasked to set up a Tableau worksheet of counts of data (ultimately to create percentages) where the contrived incoming data looks like the following.
id fruit
1 apple
1 orange
1 lemon
2 apple
2 orange
3 apple
3 orange
4 lemon
4 orange
The worksheet needs to look something like the following:
Count of ids
2 Lemons
2 No lemons
I've only been using Tableau for about 4 hours, so is this doable? Can anyone point me in the right direction?
The data is coming in from a SQL Server database in a format that I can control if that helps contribute towards a solution.
Alex's solution based on sets are very good for this scenario, but I would like to show that LODs can be more flexible if you need to extend your solution to include more categories.
for the current scenario, create a calculation with below formula and create text table using COUNTD(Id)
{FIXED [Id]:IF MAX([Fruit]='lemon') THEN 'Lemon' ELSE 'No Lemon' END}
Now for the extension part, you are considering below list where you want to count IDs with Lemon, Apple and others. Since no double counting of Ids are allowed, categorization will follow the order. (This kind of precedence will be a headache without LODs)
Now you can change your calculation as below:
{FIXED [Id]:IF MAX([Fruit]='lemon') THEN 'Lemon'
ELSEIF MAX([Fruit]='apple') THEN 'Apple'
ELSE 'No Lemon or Apple' END}
Now your visualization automatically changes to include the new category. This can be extended for any number of fruits.
This is a good use for a set.
In the data pane on the left sidebar, right click on the Id field and create a set named "Ids that contain at least one lemon" (or use a shorter less precise name)
In the set definition dialog panel, define the set by choosing "Use all" from the General tab, and then on the Condition tab, define the condition by the formula max([Fruit]="lemon")
There are many ways to think of a set, but the most abstract is just as a mathematical set of Ids that satisfy the condition. Remember each Id has many data rows, so the condition is a function of many data rows and uses the aggregation function MAX(). For booleans, True is treated as greater than False, so MAX() will return True if at least one of the data rows satifies the condition. By contrast, MIN() is True only if ALL (non-null) data rows satisfy the condition.
Once you have a set that separates your ids into Lemon scented Ids and others, then you can use that set in many ways - in calculated fields, in filters, in combination with other sets to make new sets, and of course on shelves to make visualizations.
To get a result like your question seeks, you could put your new set on the Row shelf, and put CNTD(ID) on the text shelf or columns shelf. Make sure you understand why you need count distinct (CNTD) instead of SUM([Number of Records]) here.
BTW, the LOD calculation { fixed [Id] : max([Fruit]="lemon") } is effectively the same solution.

Aggregate not populating chart correctly in SSRS

Below, I've attached a sample of my data as well as a sample of the chart output. I want to aggregate the data and include one row with this number; however, SSRS is just showing multiple of the same value.
In the example below, you'll notice there are 8 rows in Unit 1 and 8 rows in Unit 2, a
total of 13. How can I get Unit 1 to have one row which shows 8 and one row in Unit 2 to show 5? Currently, the expression is =COUNT(Fields!SubID.Value, "DataSet1").
I've also tried adding in a column full of the number 1 which I could use to Sum on, but that produced the same results.
Originally I was doing this all in SQL; that is, producing the exact output I want in SQL and then charting in SSRS. However, this is no longer a viable solution as the end user would like to be able to drill down into the details of the report. I do imagine, if there is no easy way to do this (which I feel like there has to be), that I could write two queries, having one show the report and the other show the details.
Thanks.
The second parameter of your count expression is the problem.
Don't use this:
=COUNT(Fields!SubID.Value, "DataSet1")
Try something like this instead:
=COUNT(Fields!SubID.Value, "UnitGroupName")
The group name should match what is shown in BIDS as the name you've given the grouping, such as under Row Groups.