Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for descending sorting of full text search #7496

Merged
merged 22 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ ___
- Refactor: uniform issue templates across repos (Manuel Trezza) [#7528](https://github.com/parse-community/parse-server/pull/7528)
- ci: bump ci environment (Manuel Trezza) [#7539](https://github.com/parse-community/parse-server/pull/7539)
- CI now pushes docker images to Docker Hub (Corey Baker) [#7548](https://github.com/parse-community/parse-server/pull/7548)
- Allow setting descending sort to full text queries (dblythy) [#7496](https://github.com/parse-community/parse-server/pull/7496)
- Allow cloud string for ES modules (Daniel Blyth) [#7560](https://github.com/parse-community/parse-server/pull/7560)
- docs: Introduce deprecation ID for reference in comments and online search (Manuel Trezza) [#7562](https://github.com/parse-community/parse-server/pull/7562)

Expand Down
13 changes: 13 additions & 0 deletions spec/ParseQuery.FullTextSearch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ describe('Parse.Query Full Text Search testing', () => {
}, done.fail);
});

it('fulltext descending by $score', async () => {
await fullTextHelper();
const query = new Parse.Query('TestObject');
query.fullText('subject', 'coffee');
query.descending('$score');
query.select('$score');
const results = await query.find();
expect(results.length).toBe(3);
dblythy marked this conversation as resolved.
Show resolved Hide resolved
expect(results[0].get('score'));
expect(results[1].get('score'));
expect(results[2].get('score'));
});

it('fullTextSearch: $language', done => {
fullTextHelper()
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function RestQuery(
var fields = restOptions.order.split(',');
this.findOptions.sort = fields.reduce((sortMap, field) => {
field = field.trim();
if (field === '$score') {
if (field === '$score' || field === '-$score') {
sortMap.score = { $meta: 'textScore' };
} else if (field[0] == '-') {
sortMap[field.slice(1)] = -1;
Expand Down