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: score field in query usage #275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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.parse();

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.parse();

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
Loading