teamtnt / laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch
MIT License
1.09k stars 142 forks source link

Multilingual search #305

Closed EPauli closed 1 month ago

EPauli commented 3 years ago

Hello,

I'm using Laravel Scout with TNTSearch in my website. Everything works fine so far. I have defined a toSearchableArray() function in my Page model. This function creates an array with the title and content, so TNT Search can create an index with the data.

I can search on page titles and in the page contents. I wonder if there is a feature to make the search multilingual. The site has multiple languages. When I am on the Dutch website, I only want to see Dutch pages in the search result. When I am on the English website, I only want to see the English pages in the search results.

I cannot find how I can make the TNT search index multilingual. The documentation is not clear about this. Is this possible with a callback in the search() function?

stokic commented 3 years ago

https://github.com/teamtnt/laravel-scout-tntsearch-driver#constraints maybe this could help you out? ie. where language = 'en'...

EPauli commented 3 years ago

Thank you for the response. I moved the toSearchableArray() function to another model. The pages are stored in the table 'page'. The localized data (like titles) is stored in the table 'localepage'. I moved toSearchableArray to the localepage model. That makes it easy to an extra where statement to filter on the language.

pieinn commented 3 years ago

When use with Spatie Translatable package search only within one locale