Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Normalizing keywords for search index uses wrong language #3046

Closed
ghost opened this issue Jun 28, 2018 · 4 comments
Closed

Normalizing keywords for search index uses wrong language #3046

ghost opened this issue Jun 28, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Jun 28, 2018

Description

The keywords for the search index are obviousliy built depending on the current users cp language. That should use the language of the site the entry is in.

Using Craft::$app->language in craft\helpers\Search

Steps to reproduce

  1. Create an entry with a title like 'Zauberflöte' on a site with language = german
  2. Saved by an author with cp language = en, the search index will contain 'zauberflote'. The entry will not be found by a search for 'Zauberflöte' on a german site.
  3. Saved by an author with cp language = de, the search index will contain 'zauberfloete'. Now it can be found.

Additional info

  • Craft version: 3.0.13.2
  • PHP version:
  • Database driver & version:
  • Plugins & versions:
@brandonkelly
Copy link
Member

I’m not able to reproduce this. I created a Craft install with two sites (EN and DE) with EN being the primary. Then created a section enabled for both sites, and created a new entry with DE selected, title = “Zauberflöte”. As expected the entry will show up in search results for “Zauberflöte” regardless of which site is selected.

Here is the searchkeywords table for the entry:

screen shot 2018-06-29 at 7 26 59 pm

Let me know if you can think of any other variables that could be affecting this on your site. If you’re not sure, please send your composer.json, composer.lock, and a database backup to support@craftcms.com, and tell us which section the bug is occurring on.

@ghost
Copy link
Author

ghost commented Jun 30, 2018

Thanks, but that's not the use case i tried to describe, sorry that my description was misleading.

It's about the language the author selected for his personal use in the backend.

So, if a user has this preferences:

image

and saves the item, the table shows:

image

If you change the preferences to this:

image

and resave the entry, the table content is:

image

and that is what works with this search in the german site:

image

In helpers/Search.php line 88 there is

// This will replace accented chars with non-accented chars
$map = StringHelper::asciiCharMap(true, Craft::$app->language);

where, if i don't get it wrong, $app->language is the language the cp is currently running in, and not the language of the site the entry belongs to.

I could find a temporary workaround with some configuration settings

'customAsciiCharMappingss' => [
    'a' => ['ä', 'Ä'],
    'o' => ['ö', 'Ö'],
    'u' => ['ü', 'Ü'],
    's' => ['ß']
],

but there might be some unwanted side effects (?), and it's deprecated anyway.

Thanks again for your efforts, the multilingual feature was one of the main reasons our clients switched from another wellknown CMS to Craft.

@brandonkelly
Copy link
Member

Sorry, I missed the oe in zauberfloete. I’m following the issue now – will look into it.

brandonkelly added a commit that referenced this issue Jun 30, 2018
@ghost
Copy link
Author

ghost commented Jul 4, 2018

Works now. Thanks for the quick fix.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant