mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(search): match the Meilisearch result window to Elasticsearch (#1646)
This commit is contained in:
1 parent
004fb0c7b0
commit
5022568608
2 files changed
+18
-8
No files matched your search
@@ -29,7 +29,7 @@ class FakeMeilisearchClient implements MeilisearchClient {
|
||||
this.indexExists = true;
|
||||
return this.nextTask() as TResponse;
|
||||
}
|
||||
if (method === 'PUT' && path.includes('/settings/')) {
|
||||
if ((method === 'PUT' || method === 'PATCH') && path.includes('/settings/')) {
|
||||
return this.nextTask() as TResponse;
|
||||
}
|
||||
if (method === 'POST' && path.endsWith('/documents')) {
|
||||
@@ -75,8 +75,12 @@ describe('MeilisearchMessageAdapter', () => {
|
||||
'PUT /indexes/messages/settings/searchable-attributes',
|
||||
'PUT /indexes/messages/settings/filterable-attributes',
|
||||
'PUT /indexes/messages/settings/sortable-attributes',
|
||||
'PATCH /indexes/messages/settings/pagination',
|
||||
]);
|
||||
expect(client.waitedTaskUids).toEqual([1, 2, 3, 4]);
|
||||
expect(client.waitedTaskUids).toEqual([1, 2, 3, 4, 5]);
|
||||
expect(client.requests.find((request) => request.path.endsWith('/settings/pagination'))?.body).toEqual({
|
||||
maxTotalHits: 10000,
|
||||
});
|
||||
});
|
||||
|
||||
it('builds Meilisearch search requests from message filters', async () => {
|
||||
@@ -127,6 +131,6 @@ describe('MeilisearchMessageAdapter', () => {
|
||||
|
||||
expect(client.waitedTaskUids).toEqual([]);
|
||||
await adapter.refreshIndex();
|
||||
expect(client.waitedTaskUids).toEqual([4]);
|
||||
expect(client.waitedTaskUids).toEqual([5]);
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import {joinMeiliFilters} from './MeilisearchFilterUtils';
|
||||
import type {MeilisearchIndexDefinition} from './MeilisearchIndexDefinitions';
|
||||
|
||||
const MAX_SEARCH_LIMIT = 1000;
|
||||
const MAX_TOTAL_HITS = 10000;
|
||||
|
||||
interface MeilisearchIndexAdapterOptions<TFilters> {
|
||||
client: MeilisearchClient;
|
||||
@@ -57,9 +58,10 @@ export class MeilisearchIndexAdapter<
|
||||
await this.waitForTask(task.taskUid);
|
||||
}
|
||||
await Promise.all([
|
||||
this.applySetting('searchable-attributes', this.indexDefinition.searchableAttributes),
|
||||
this.applySetting('filterable-attributes', this.indexDefinition.filterableAttributes),
|
||||
this.applySetting('sortable-attributes', this.indexDefinition.sortableAttributes),
|
||||
this.applySetting('PUT', 'searchable-attributes', this.indexDefinition.searchableAttributes),
|
||||
this.applySetting('PUT', 'filterable-attributes', this.indexDefinition.filterableAttributes),
|
||||
this.applySetting('PUT', 'sortable-attributes', this.indexDefinition.sortableAttributes),
|
||||
this.applySetting('PATCH', 'pagination', {maxTotalHits: MAX_TOTAL_HITS}),
|
||||
]);
|
||||
this.initialized = true;
|
||||
}
|
||||
@@ -177,9 +179,13 @@ export class MeilisearchIndexAdapter<
|
||||
}
|
||||
}
|
||||
|
||||
private async applySetting(setting: string, value: Array<string>): Promise<void> {
|
||||
private async applySetting(
|
||||
method: 'PUT' | 'PATCH',
|
||||
setting: string,
|
||||
value: Array<string> | {maxTotalHits: number},
|
||||
): Promise<void> {
|
||||
const task = await this.client.request<MeilisearchTask>(
|
||||
'PUT',
|
||||
method,
|
||||
`/indexes/${encodeURIComponent(this.indexDefinition.uid)}/settings/${setting}`,
|
||||
value,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user