searchWhere, accent insensitive in addition of the case

Hello,

The searchWhere is a really useful function to search through your content easily.

However, just removing the case for search is not enought for all languages dealing with accent. I think the search search should also be accent insensitive.

Best regards,

Alex

Hi @PubliAlex

Thanks for the idea. Unfortunately, there isn’t enough information in this post for it to be actionable. We need to see some code, with something like expectation vs reality.

Ok lets imagine a blog system with a search. The blog post have the following fields :

  • title
  • teaser
  • content

I created a blog post with the following title : “Mon actualité” and some lorem ipsum in content.

Here is the query when you fill something in the search input.

    {% set records = posts.searchWhere(post('search'), ['title', 'content']).paginate(3) %}

If I search the word “Actualité”, it works cause it’s case insensitive
If I search the word “actualite”, it doesn’t work because of the “e” instead of “é”

In all search engine, accent is not considered when you search something because lot of people don’t type them. So, in the case above, when you search the word “actualite” the post with “actualité” in the title should be considered as a valid result.

The invert case is also true, if the post title have “actualite” and you search “actualité”, it should also be considered as a valid result.

I hope it’s more clear with an use case.

did u tried whereLike ? that will be case insensitive and of course, it will pick anything without special characters etc.

Thank you for the answer. I didn’t know the whereLike method. I don’t find how to use it in twig like the searchWhere method, do you have an example ?

depends on, what type of data you got in that posts… if it is instance of model, you can use anything related to that model, if it is collection, then probably you can filter data inside collection. when it is a query builder, you can use query builder methods to perform anything what you want. of course, it is not a good idea to assign any of these (only collection of results) to twig, but… u know…

This is called transliteration.

> Str::transliterate('Actualité')
= "Actualite"

SQL would need to apply this function since the data is stored there. I’m not sure there is a function that does this, unfortunately.

You would need to provide a secondary attribute that transliterates all the content and searches that in addition to the original attribute.

Don’t you think that rainlab.translate would be the perfect plugin to host a method that would facilitate query on words with accent ?

Don’t think that the core multisite feature would be the right place cause you can have multisite websites that does not deal with different languages, but the rainlab.translate seems to be the perfect place.

Best regards,

Alex

A trait/behavior is probably best for this. One that automatically transliterates defined attributes, and then you include them in your search.