Hey folks. I have a use-case where I want to sort ...
# orm-help
a
Hey folks. I have a use-case where I want to sort my values on the basis of relevance. Now, relevance is calculated based on filters. The rows matching more of the filters should be considered more relevant. Ideally, I would like to provide a method to compute this value for each row and add it under a column like
relevance
, and then pass
relevance
for
orderBy
. We are also using pagination. Which is why it is very important to have the sorting bit done using Prisma's native sorting support. Something like this would be ideal:
Copy code
this.prisma.job.map((job) => { ...job, relevance: calculateRelevance(job) }).findMany({ orderBy: relevance })
I tried reading the docs to search for something that might work but couldn't find something to match this use case. Does anyone have any suggestions for how I can go about this? Or do you recommend a different approach?
👀 1
a
Hey there! You would need to fetch all jobs and compute the
relevance
separately. Then you could update the rows with the new
relevance
data.
a
Hey Austin. Thanks for getting back to me. Since this relevance score corresponding to each job will be different for every user (since every user might use a different set of filters), it doesn't seem feasible to keep saving the relevance score for each user and then, updating it for another user. What do you think? In the case that we cannot add it to a row's value, is there is a way to separately apply pagination on a list of fetched jobs instead of doing it through findMany?
a
is there is a way to separately apply pagination on a list of fetched jobs instead of doing it through findMany
Could you explain this a little more?