diff --git a/scripts/update-settings.ts b/scripts/update-settings.ts index 3953dc0..948ab13 100644 --- a/scripts/update-settings.ts +++ b/scripts/update-settings.ts @@ -18,15 +18,15 @@ const DESCRIPTION_MAXIMUM_WORDS = 100 const indexesConfig = [ { indexName: 'movies-en-US', - documentTemplate: `A movie titled '{{doc.title}}' {{ doc.release_date | date: '%B %d, %Y' }} whose description starts with {{doc.overview|truncatewords: ${DESCRIPTION_MAXIMUM_WORDS}}}`, + documentTemplate: `A movie titled '{{doc.title}}', released in {{ doc.release_date | date: '%B %d, %Y' }}, whose description starts with {{doc.overview|truncatewords: ${DESCRIPTION_MAXIMUM_WORDS}}}`, }, { indexName: 'movies-ja-JP', - documentTemplate: `タイトルが '{{doc.title}}' で、概要が {{doc.overview|truncatewords: ${DESCRIPTION_MAXIMUM_WORDS}}} で始まる映画`, + documentTemplate: `映画のタイトルは '{{doc.title}}' で、{{ doc.release_date | date: '%Y年%m月%d日' }}に公開され、{{doc.overview|truncatewords: ${DESCRIPTION_MAXIMUM_WORDS}}}`, }, { indexName: 'movies-th-TH', - documentTemplate: `ภาพยนตร์ชื่อ '{{doc.title}}' ซึ่งมีคำอธิบายขึ้นต้นด้วย {{doc.overview|truncatewords: ${DESCRIPTION_MAXIMUM_WORDS}}}`, + documentTemplate: `หนังชื่อ '{{doc.title}}' ฉายเมื่อ {{ doc.release_date | date: '%d %B %Y' }} ซึ่งเริ่มต้นด้วย {{doc.overview|truncatewords: ${DESCRIPTION_MAXIMUM_WORDS}}}`, }, ] diff --git a/src/lib/createMeilisearchClient.ts b/src/lib/createMeilisearchClient.ts new file mode 100644 index 0000000..8418656 --- /dev/null +++ b/src/lib/createMeilisearchClient.ts @@ -0,0 +1,15 @@ +import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' + +export const createMeilisearchClient = (host: string, apiKey: string) => { + return instantMeiliSearch(host, apiKey, { + primaryKey: 'id', + finitePagination: true, + meiliSearchParams: { + // ⬇️ Hybrid search configuration + hybrid: { + embedder: 'default', + semanticRatio: 0.5, + }, + }, + }) +} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index b135008..1286d2b 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useEffect } from 'react' import styled from 'styled-components' import Head from 'next/head' import { InstantSearch, useInstantSearch } from 'react-instantsearch' -import { instantMeiliSearch } from '@meilisearch/instant-meilisearch' import type { InstantMeiliSearchObject } from '@meilisearch/instant-meilisearch' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' @@ -15,6 +14,7 @@ import MoviesList from 'components/MoviesList/index' import { LANGUAGES } from 'data/constants' import { LanguageProvider } from 'context/LanguageContext.ts' import useLocalStorage from 'hooks/useLocalStorage' +import { createMeilisearchClient } from '../lib/createMeilisearchClient' const MEILISEARCH_HOST = process.env.MEILISEARCH_HOST || 'http://0.0.0.0:7700' const MEILISEARCH_API_KEY = process.env.MEILISEARCH_API_KEY || 'searchKey' @@ -82,18 +82,7 @@ const Home = ({ host, apiKey }) => { React.useEffect(() => { if (host && apiKey) { - setClient( - instantMeiliSearch(host, apiKey, { - primaryKey: 'id', - finitePagination: true, - meiliSearchParams: { - hybrid: { - semanticRatio: DEFAULT_SEMANTIC_RATIO, - embedder: DEFAULT_EMBEDDER, - }, - }, - }) - ) + setClient(createMeilisearchClient(host, apiKey)) } }, [host, apiKey])