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.

Comments

sutharsan’s picture

Status: Active » Needs review
StatusFileSize
new2.22 KB
das-peter’s picture

Status: Needs review » Reviewed & tested by the community

I 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 :)

kekkis’s picture

I see no problems either, testing revealed no problems on the language combo fi/en/sv. Therefore RTBC on my behalf.

thepanz’s picture

I 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.

thepanz’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new6.16 KB

Rerolled 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).

thepanz’s picture

Reworked patch: we need to rebuild the index when the "restrict undefined" setting changes.

thepanz’s picture

Fixed missing include in patch.

  • thePanz committed 06aa4f2 on 7.x-2.x
    Issue #2386457 by thePanz, Sutharsan, das-peter, olofjohansson:...
thepanz’s picture

Status: Needs review » Active

Latest patch has been merged; No upgrade path from the alpha1 release has been implemented.
You must update your Index settings to use this feature.

thepanz’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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