Duplicate search results have been reported and discussed in other issues before, but I have taken a different route for a solution. That's why I create a separate issue for this solution.
To reproduce my situation:
* Use a Drupal site with English and Dutch
* Create a content type with entity translation.
* Allow Language Neutral for this content type
* Make some fields translatable (Body and Title (Title module)) and some fields not translatable (Taxonomy term reference).
* Use Solr as search engine
* Add Body, Title and taxonomy fields to the search index.
* On the index set the 'Languages to be included in the index' to 'All entity languages'.
* Create one English node and one Dutch node.
* Make a view based on the multilingual search index (Search API Views module) that filters on 'Current user language' or 'Language neutral'
* Observe that the view shows duplicate records both in Engels and in Dutch user interface language.
When debugging this issue, I noticed that the Solr index contains items for both language (English and Dutch) as well as language neutral. For example item_ids 'en_123', 'nl_123' and 'und_123'. Because the view filter allows language neutral, this will result in duplicates (English: 'en_123' -> node/123, 'und_123' -> node/123).
The solution in this issue is to prevent language neutral to be added to the index when the node is translated, i.e. the node language is English or Dutch. A language neutral item is only added to the index when the node language is language neutral. For this purpose a new option is add to the 'Languages to be included in the index' selector.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | search_api_et-language-undefined-index-2386457-7.patch | 7.51 KB | thepanz |
Comments
Comment #1
sutharsan commentedComment #2
das-peter commentedI like this approach as it also avoids unnecessary indexing of items!
Visual review looks good, tested in local env with a bunch of nodes and a search api views setup. No more duplicates, less items to index.
Beautiful :)
Comment #3
kekkisI see no problems either, testing revealed no problems on the language combo fi/en/sv. Therefore RTBC on my behalf.
Comment #4
thepanz commentedI would like to integrate the code from #2396475: Indexed languages should be determined using the translations, thus having a better overview the different translation settings.
Will provide a patch later.
Comment #5
thepanz commentedRerolled patch, I merged the two issues and exposed the setting "Restrict Undefined" as a checkbox.
To test the patch, apply it on latest -dev and update the index configuration by ticking the new checkbox; sometimes the index must be disabled and then re-enabled to properly get the new settings (for already existing entities).
Comment #6
thepanz commentedReworked patch: we need to rebuild the index when the "restrict undefined" setting changes.
Comment #7
thepanz commentedFixed missing include in patch.
Comment #9
thepanz commentedLatest patch has been merged; No upgrade path from the alpha1 release has been implemented.
You must update your Index settings to use this feature.
Comment #10
thepanz commented