smartfuzzy/test/test.articlesearch.ts

35 lines
1000 B
TypeScript
Raw Normal View History

import { expect, tap } from '@push.rocks/tapbundle';
2021-10-03 17:12:02 +02:00
import * as tsclass from '@tsclass/tsclass';
import * as smartfuzzy from '../ts/index.js';
2021-10-03 17:12:02 +02:00
tap.test('should sort objects', async () => {
const articleArray: tsclass.content.IArticle[] = [
{
title: 'Berlin has a ambivalent history',
content: 'it is known that Berlin has an interesting history',
author: null,
tags: ['city', 'Europe', 'hello'],
timestamp: Date.now(),
featuredImageUrl: null,
2021-10-03 17:37:03 +02:00
url: null,
2021-10-03 17:12:02 +02:00
},
{
title: 'Washington is a great city',
content: 'it is known that Washington is one of the greatest cities in the world',
author: null,
tags: ['city', 'USA', 'hello'],
timestamp: Date.now(),
featuredImageUrl: null,
2021-10-03 17:37:03 +02:00
url: null,
},
2021-10-03 17:12:02 +02:00
];
const testArticleSearch = new smartfuzzy.ArticleSearch(articleArray);
const result = await testArticleSearch.search('USA');
console.log(result);
2021-10-03 17:37:03 +02:00
console.log(result[0].matches);
2021-10-03 17:12:02 +02:00
});
tap.start();