I have a list of job openings. I'm using Algolia's instantsearch.js library to render search results through these jobs.
Right now they render one-per-line:
company.name, job.title
company.name, job.title
company.name, job.title
I'd like for them to render like Algolia describes here (they even use a job listing as an example)
https://www.algolia.com/doc/guides/search/distinct#how-distinct-works
company.name
job.title
job.title
job.title
My question is: how do I render these distinct/grouped results using instantsearch.js?
I had hoped that once I enable 'distinct', Algolia would return it's hits in a grouped-by fashion, but it is still being returned as a flat-file list of jobs (just with a _distinctSeqID attribute)
Am I doing something wrong, or is it the actual intention that I take care of the grouping myself in my frontend. If so, is there a real purpose to the distinct method?
Ideally, I would have Algolia adding example code for the specific example they give there, being the job listing. But that is currently not the case.
Thanks!
Related
I'm trying to implement some kind of a basic social network project. It has Posts, Comments and Likes like any other.
A post can have many comments
A post can have many likes
A post can have one author
I have a /posts route on the client application. It lists the Posts by paginating and shows their title, image, authorName, commentCount and likesCount.
The graphql query is like this;
query {
posts(first: 10, after: "123456") {
totalCount
edges {
node {
id
title
imageUrl
author {
id
username
}
comments {
totalCount
}
likes {
totalCount
}
}
}
}
}
I'm using apollo-server, TypeORM, PostgreSQL and dataloader. I use dataloader to get author of each post. I simply batch the requested authorIds with dataloader, get authors from PostgreSQL with a where user.id in authorIds query, map the query result to the each authorId. You know, the most basic type of usage of dataloader.
But when I try to query the comments or likes connection under each post, I got stuck. I could use the same technique and use postId for them if there was no pagination. But now I have to include filter parameters for the pagination. And there maybe other filter parameters for some where condition as well.
I've found the cacheKeyFn option of dataloader. I simply create a string key for the passed filter object to the dataloader, and it doesn't duplicate them. It just passes the unique ones to the batchFn. But I can't create a sql query with TypeORM to get the results for each first, after, orderBy arguments separately and map the results back to the function which called the dataloader.
I've searched the spectrum.chat source code and I think they don't allow users to query nested connections. Also tried Github GraphQL Explorer and it lets you query nested connections.
Is there any recommended way to achieve this? I understood how to pass an object to dataloader and batch them using cacheKeyFn, but I can't figure out how to get the results from PostgreSQL in one query and map the results to return from the loader.
Thanks!
So, if you restrict things a bit, this is doable. The restriction is to only allowed batched connections on the first page of results, e.g. so all the connections you're fetching in parallel are being done with the parameters. This is a reasonable constraint because it lets you do things like get the first 10 feed items and the first 3 comments for each of them, which represents a fairly typical use case. Trying to support independent pagination within a single query is unlikely to fulfil any real world use cases for a UI, so it's likely an over-optimisation. With this in mind, you can support the "for each parent get the first N children" use case with PostgreSQL using window.
It's a bit fiddly, but there are answers floating around which will get you in the right direction: Grouped LIMIT in PostgreSQL: show the first N rows for each group?
So use dateloader how you are with cacheKeyFn, and let your loader function recognise whether you can perform the optimisation (e.g. after is null and all other arguments are the same). If you can optimise, use a windowing query, otherwise do unoptimised queries in parallel as you would normally.
Has anyone found a workaround to allow them to Sort query results using tags in VSO?
The support page clearly states that Excel (as an export should be used).
FYI: https://www.visualstudio.com/en-us/docs/work/track/add-tags-to-work-items
I was hoping someone found a way to sort based on tags where the result is:
- Tag #1
- Feature
- Feature
- Feature
- Tag #2
- Feature
- Feature
- Feature
You can define the query with the clause Tags Contains tagname. If you want to query more than one tag, you can continue add the same clauses with OR operation. Such as query tags t1 and t3 in the query, you can define as:
But the result can’t be ordered by Tags, Which I post an user voice order query result by Tags , you can vote and follow up.
Besides, you can also filter the WIT in Kanban board.
In my template I have a country select box, and province element which changed dynamically based on country. For example, If I select United States, Province will be a selectbox which include US States. If i select other country, Province will be only a text field. I know that I have to do that by Javascript but I want to know the best practice in this case. Any suggestion?
This question arises almost daily on stackoverflow ... How to handle sub-select's like country->state ...?
Best practice for multiple related select field types is only loading the first selectbox from database with a dedicated submit button for adding the subselects - could be "show states" or similar in your case.
Don't fetch all the possible sub-selects when rendering the form the first time. This could easily lead to heavy database queries if you show something like country -> state -> city for example ... but country -> state for all countries is already too much.
If the form was submitted using the "show states" button add the related sub-select to the form together with either a "show cities" button or if no other sub-selects will be loaded .. with the final "save" button.
This way a user without JavaScript can use the double-select without the at first unneeded subselect queries involved. Just hiding the second select with JS is not best practice.
Progressive enhancement through JavaScript would then be AJAX-Loading i.e. a JSON list of the states for a country, removing the "show states" button , rendering the data using JS templating engines like handlebars or mustache and adding the "save" button.
This way you don't have to send too much repetetive data to the client browser ( option,option,option ... ).
Last step would be caching client and server-side to speed up the loading times - maybe even involve some kind of background preloading i.e. the top 5 choices for the client's preferred language.
I have a report that uses a query of input controls. It is a drop-down menu of specific ID's (ie. 28, 13, 30...) I want to know if it is possible to have my report go through each of these parameters and populate the report one page at a time for each of them.
Here is an example of the different parameters I want the report to loop through:
Do you want to create a page for all Partner IDs? Or just for the Partner IDs that a user selects? Either is possible.
Using all Partner IDs is probably easier. Modify your report query which probably has something like WHERE partner_id = $P{partnerID}. Remove the where clause. Add grouping and sorting to the query to group on partner id. Each group can start on a new page. And now you don't need a parameter at all.
If you want the user to select the Partner IDs, then you need to use a multi-select input control rather than the single-select input control you're using now. Update your query to use something like this: WHERE $X{IN, partner_id, partnerID}. Add grouping and sorting as above.
What I really need is a Tabular form that allows me to update multiple rows at a time while being filterable like an Interactive report. Any chance this is even remotely possible?
I would also like to hijack the row checkboxes on a tabular form that appear when the 'delete' functionality is activated and use them to select which rows get assigned a to a group based on a common attribute. (i.e. My table contains parts in my inventory and I need to be able to assign parts with common attributes to a group for processing)
Perhaps a group-by function that creates a new row in a 'Group' table with the group as the PK and the parts assigned to that group as a list or something...?
Thoughts? I am kind of at a loss...
It's really not that hard :) You can easily transform an IR into a pseudo-tabular form. And even though there are always more stylish and elegant solutions, those usually involve lots of javascript and/or plugins. They're nice, but not always what you want or need of course.
So how to manipulate your output? Use the APEX_ITEM api!
Quick example. I have an ir built on emp. I added a checkbox and textbox.
select empno, ename, deptno,
apex_item.checkbox(1, empno) empno_selected,
apex_item.text(2, ename, 10, 10) ename_edit
from emp
Don't forget: in the column attributes, set Display text as to Standard Report Column. If you don't, the output will be in plain text. Since apex_item generates html code, you don't want the plain text of course :)
Now, to be able to perform DML based on the actions you do in those generated fields, you will need a process. Let me start off by pointing out though that the generated items are stored in application variables, namely in arrays in APEX_APPLICATION.
Take note of the behaviour of checkboxes: only ticked boxes will have their value stored in the array!
As an example, i've made this small On Submit process (also adding a SUBMIT button on the form to actually perform the submit...)
for i in 1..apex_application.g_f01.count
loop
insert into empselected(empno, selectiondate, ename_changed)
values(apex_application.g_f01(i), sysdate, apex_application.g_f02(i));
end loop;
This will loop over the records with the checkboxes ticked, and insert them into some table. For example, i ticked the box with KING and edited the textfield. See record nr 2 (1 is from a previous action ;))
It's not all the way there yet though. You still miss out on the functionality of a tabular form and it's processes, and things like optimistic locking. If you want to stay with tabular forms, you can also, for example, check out this link. There have also been some questions here about writing your own mru processes etc, like this one ;)
It is possisble, using the same tabular form.
Create an item (text item) in the tabular form region.
Create a submit button (Create a button displayed among this region's items)
Modify the where clause in the tabular form region source
For Example, you need search by customer name:
WHERE lower(CUSTOMER_NAME) LIKE '%'||lower(nvl(:PXX_SEARCH,CUSOTOMER_NAME))||'%'
If you need to search for other field only add other condition to the where clause
WHERE (
lower(CUSTOMER_NAME) LIKE '%'||lower(nvl(:PXX_SEARCH,CUSOTOMER_NAME))||'%'
or lower(CUSTOMER_address) LIKE '%'||lower(nvl(:PXX_SEARCH,CUSOTOMER_NAME))||'%'
)
Simple and use the same tabular form.