typesense-utils
Version:
A list of utilities for typesense search engine
78 lines (77 loc) • 2.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const buildSortBy_1 = require("./buildSortBy");
describe('buildSortBy', () => {
it('sorts by field', () => {
expect((0, buildSortBy_1.buildSortBy)({
title: {
$order: buildSortBy_1.Order.Asc,
$null: buildSortBy_1.NullOrder.First,
},
price: {
$order: buildSortBy_1.Order.Desc,
$null: buildSortBy_1.NullOrder.Last,
},
})).toBe('title(missing_values:first):asc,price(missing_values:last):desc');
});
it('sorts by _text_match with buckets and bucket_size', () => {
expect((0, buildSortBy_1.buildSortBy)({
_text_match: {
$order: buildSortBy_1.Order.Desc,
$buckets: 10,
$bucket_size: 3,
},
weighted_score: {
$order: buildSortBy_1.Order.Desc,
},
})).toBe('_text_match(buckets:10,bucket_size:3):desc,weighted_score:desc');
});
it('sorts by geopoint', () => {
expect((0, buildSortBy_1.buildSortBy)({
location: {
$point: [40.711475, -73.998399],
$order: buildSortBy_1.Order.Asc,
},
})).toBe('location(40.711475,-73.998399):asc');
});
it('sorts by geopoint with precision', () => {
expect((0, buildSortBy_1.buildSortBy)({
location: {
$point: [40.711475, -73.998399],
$order: buildSortBy_1.Order.Desc,
$precision: 1,
},
})).toBe('location(40.711475,-73.998399,precision:1km):desc');
});
it('sorts by geopoint with excluded radius', () => {
expect((0, buildSortBy_1.buildSortBy)({
location: {
$point: [40.711475, -73.998399],
$order: buildSortBy_1.Order.Desc,
$exclude_radius: 1,
},
})).toBe('location(40.711475,-73.998399,exclude_radius:1km):desc');
});
it('sorts by condition', () => {
expect((0, buildSortBy_1.buildSortBy)({
_eval: [
{
$expr: {
title: {
$eq: 'The Witcher',
},
},
$order: buildSortBy_1.Order.Asc,
},
{
$expr: {
available: {
$eq: true,
},
},
$order: buildSortBy_1.Order.Desc,
},
],
})).toBe('_eval(title:=`The Witcher`):asc,_eval(available:=true):desc');
});
});