I think #2044415: Proper language/translation support is probably also something we should implement before we move this to the proper Search API project. Basically, it's just about making the functionality of Search API ET the normal behavior of the content entity datasources integrated into this module – i.e., instead of providing one "search item" per entity, we provide one per each translation of an entity. Item IDs would then therefore change to a tupel of entity IDand language – e.g., "1:en", "1:de", "2:en", …

I was previously unsure whether to do this in this module, or just provide a sounder basis for Search API ET, but talking about it in Szeged nearly everyone agreed that the Search API has to support translations by default. In Drupal 8, everything else would be a bug, not just a missing feature.

One thing we could add then, too, is a config option for datasources stating which languages should be indexed. But this can of course also be added later (even post-release, in theory), more important is the basic functionality.

What we will also have to add again is the search_api_language field – this time as a processor, though, which we'd hard-code as always enabled for now (until we have a flexible system for doing that – see #2090341: Add a way for marking fields/processors as "locked" or "hidden").

CommentFileSizeAuthor
#8 2241429-followup.patch991 bytesamateescu
#5 2241429-test.patch9.81 KBamateescu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Issue summary: View changes

What we will also have to add again is the search_api_language field – this time as a processor, though, which we'd hard-code as always enabled for now (until we have a flexible system for doing that – see #2090341: Add a way for marking fields/processors as "locked" or "hidden").

drunken monkey’s picture

Assigned: Unassigned » drunken monkey

I'm going to work on this today. First going to start with the processor, I think.
We also want to add setLanguages() and getLanguages() methods for the query.

drunken monkey’s picture

Assigned: drunken monkey » Unassigned

OK, I finished the "Item language" processor, along with its hard-code "required" hack and tests, as well as having one search item per translation of an entity.

Missing still are tests for the latter, and a "languages" setting for the content entity datasource (as well as tests for that).

amateescu’s picture

Assigned: Unassigned » amateescu

Working on those tests.

amateescu’s picture

FileSize
9.81 KB

Committed the test attached for the "one item per entity language functionality", which already found a bug :)

amateescu’s picture

Assigned: amateescu » Unassigned
Status: Active » Fixed

Since the issue summary says that the 'languages' setting for the content entity datasource can be added later, I guess the main scope of this issue is done so I'm going to mark it fixed and open a non-"move to home repository" blocking followup for it.

drunken monkey’s picture

Thanks a lot, great work, and good thinking on the new issue!
Just one question:

+++ b/search_api.module
@@ -94,12 +94,12 @@ function search_api_entity_update(EntityInterface $entity) {
     foreach ($updated_item_ids as $i => $langcode) {
-      if (!isset($old_translations[$langcode])) {
+      if (!in_array($langcode, array_keys($old_translations))) {

Can these translation objects ever be NULL? Or what is the difference here?
In any case, I guess array_key_exists() would then be the better option.

amateescu’s picture

Component: Backend » Framework
FileSize
991 bytes

Nope, those objects can never be null :)

The problem there was that we should've been checking the values of those array, not it's keys. (the keys are numeric, the values are langcodes). Committed this small patch to try and make things a bit more clear.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.