Skip to content

Commit

Permalink
Merge pull request #514 from meilisearch/webinar
Browse files Browse the repository at this point in the history
Update document template
  • Loading branch information
Strift authored Apr 22, 2024
2 parents c0713f0 + 198f691 commit 86f692b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions scripts/update-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}`,
},
]

Expand Down
15 changes: 15 additions & 0 deletions src/lib/createMeilisearchClient.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
})
}
15 changes: 2 additions & 13 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit 86f692b

Please sign in to comment.