Skip to content

Commit

Permalink
fix: score field in query usage
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Sep 4, 2024
1 parent d7f2c03 commit 002a74f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion packages/admin-sdk/src/data/Criteria.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Test Criteria class', () => {
});

it('should respect altered default values', () => {
setDefaultValues({limit: 42});
setDefaultValues({ limit: 42 });
const criteria = new Criteria();

expect(criteria.getLimit()).toBe(42);
Expand All @@ -23,4 +23,28 @@ describe('Test Criteria class', () => {
criteria.setTitle('foo');
expect(criteria.getTitle()).toBe('foo');
});

test('add query', () => {
const criteria = new Criteria();

criteria.addQuery(Criteria.equals("foo", "bar"), 100);

const obj = criteria.toPayload();

expect(obj.query).toEqual([
{ score: 100, query: { type: "equals", field: "foo", value: "bar" } },
]);
});

test('add query with score field', () => {
const criteria = new Criteria();

criteria.addQuery(Criteria.equals("foo", "bar"), 100, 'test');

const obj = criteria.toPayload();

expect(obj.query).toEqual([
{ score: 100, query: { type: "equals", field: "foo", value: "bar" }, scoreField: 'test' },
]);
});
});
4 changes: 2 additions & 2 deletions packages/admin-sdk/src/data/Criteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ interface Association {
interface Query {
score: number,
query: SingleFilter,
[scoreField: string]: unknown,
scoreField?: string
}
interface Sorting {
field: string,
Expand Down Expand Up @@ -387,7 +387,7 @@ export default class Criteria {
const query: Query = { score: score, query: filter };

if (scoreField) {
query[scoreField] = scoreField;
query.scoreField = scoreField;
}

this.queries.push(query);
Expand Down

0 comments on commit 002a74f

Please sign in to comment.