typesense / typesense/typesense

sort_by is being ignored when getting search results

Open
#970 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
26.6k
Forks
973
Avg merge
18h 45m
Merged PRs (30d)
4

Description

Description

Okay So first thank you for this software solution, you guys are amazing!

but I'm facing a certain issue that is not fatal yet necessary for my application. I'm using Typesense with Firebase cloud functions (created a cloud function with the Typesense JavaScript code which ill post now). The Search function is working perfectly and well, but when I try to add a "sort by" option to the search parameters, the sort by is getting completely ignored, actually, I tried using filter by too, and was ignored too with no Error code or any signs of failures. I do not know what to do, to be honest. Please help

Cloud function with the Typesense Function:

const Typesense=require('typesense');

const functions = require("firebase-functions");

let client = new Typesense.Client({
'nodes': [{
'host': 'xxx', // where xxx is the ClusterID of your Typesense Cloud cluster
'port': 'xxx',
'protocol': 'https'
}],
'apiKey': 'xxx',
'connectionTimeoutSeconds': 10
})

exports.returnSearchResults =functions.https.onRequest(async (request, response) => {
if (request.method === 'OPTIONS') {
response.set('Access-Control-Allow-Headers', "authorization,content-type");
response.set('Access-Control-Allow-Origin', '');
response.status(204).send('');
}else{
let search = {
'q' : request.body.query,
'query_by':"tags,productName,productDescription",
"page": request.body.page,
"per_page": request.body.documentLimit,
"sort_by":"productAvailableQuantity:desc" ,
}
client.collections('Products')
.documents()
.search(search)
.then(function (searchResults) {
response.set('Access-Control-Allow-Headers', "authorization,content-type");
response.set('Access-Control-Allow-Origin', '
');
response.status(200).send(searchResults);
})

}

});

Expected Behavior

The expected behavior is that the products with the most available quantity should appear first

Actual Behavior

The actual behavior is that the sort_by is completely ignored.

Screen Shot 2023-04-10 at 12 52 44 PM

Typesense Version:

Server: 0.24.1
typesense-js: 1.5.3

OS:

Mac

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the search request from the provided Firebase Cloud Function using Typesense Server 0.24.1 and typesense-js 1.5.3. Investigate why the sort_by and filter_by parameters are ignored; done means the expected parameters affect returned results or the request produces a clear error.

Written by the indexing model from the issue text.

Assessment

Tech stack
firebase, javascript
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.