Problem/Motivation

When searching for content in a multilingual website, Drupal core display results in all languages.

This maybe considered a blocking issue to resolve #3041039: Search for content in current language or a duplicate of that one.

Proposed resolution

When no language is chosen in advance-search, display results only in current language.

Remaining tasks

Create a patch.

Comments

shaal created an issue. See original summary.

shaal’s picture

Status: Active » Needs review
StatusFileSize
new1.96 KB

Created a patch that checks if any language is selected in advanced search options.
If not - it adds a filter of current_language (+ undefined language + n/a language).

I tested it with Umami demo,
As an anonymous user, using the English interface, search for the word 'chocolate'.
3 results in English should be displayed.
Change the language to Spanish, and search for 'chocolate' again,
3 results in Spanish should be displayed.

Log in as admin, using the English interface, search for the word 'chocolate'.
(3 results in English should be displayed)

In the search results page, open the 'Advanced Search' options, choose English, and click the "Advanced Search" button
(3 results in English should be displayed)
Choose 'English' in "Languages" options, and click the "Advanced Search" button
(3 results in English should be displayed)
Choose 'Spanish' in "Languages" options, and click the "Advanced Search" button
(3 results in Spanish should be displayed)
Choose both 'English' and 'Spanish' in "Languages" options, and click the "Advanced Search" button
(6 results in both English and Spanish should be displayed)

Status: Needs review » Needs work

The last submitted patch, 2: search-current-language-3045362-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jasonawant’s picture

Issue summary: View changes
Status: Needs work » Needs review

Hi Shaal!

Thanks for the patch and referencing the related issue #3041039: Search for content in current language. These maybe duplicates of each other, but I'll leave that for someone else to decide.

I've updated the issue summary so someone can see this related issue more prominently.

I've changed the status to Needs Review to hopefully get some eyes on it. To me this seems like a fine path forward that will needs tests associated with it.

I think we'll need to get consensus on the path forward first before putting time into tests.

pawandubey’s picture

Status: Needs review » Needs work

@shaal

Please find the below feedback of patch#2:

1. All the test cases which you have mentioned is working fine and tested for both anonymous and admin user.

2. Strange things I have found is that when you open the advance search and put keyword 'chocolate' with English language then you will find total 3 result as expected but in the normal Search box you will get two keywords 'chocolate chocolate' which gets increase if you put the same in the advance search.

3. Normal Search (en/search/node) : At the same time in the normal search keyword, search only with 'chocolate' and you will get the 3 results as expected. Now open the Advance search and select both languages and click on the normal search button and you will get total 6 results in this case. As per my understanding Search and Advance Search both shouldn't be mixed up in this case. The issue related to search URL where the keywords just getting added and not cleared. Need to work on this.

4. Patch#2 also needs changes related to coding standard which you can find from the codesniffer_fixes.patch result in your patch.

shaal’s picture

Version: 8.7.x-dev » 8.8.x-dev
StatusFileSize
new1.96 KB

Thank you @pawandubey for the review in #5

This patch is a re-roll for Drupal 8.8, and includes 3 coding standard issues.
(no interdiff)

5.2
I couldn't replicate:

in the normal Search box you will get two keywords 'chocolate chocolate' which gets increase if you put the same in the advance search.

Can you please test it again? add screenshots? steps to replicate?

5.3
This is the expected result.
By default, the search returns results only in the current language, but if you open the advanced search box and choose specific languages it will return results in the chosen languages.

5.4
Fixed in this patch.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

chandrashekhar_srijan’s picture

Status: Needs work » Needs review
StatusFileSize
new5.74 KB
new3.46 KB

Fixed all the failures.

Status: Needs review » Needs work

The last submitted patch, 10: 3045362-10.patch, failed testing. View results

chandrashekhar_srijan’s picture

Status: Needs work » Needs review
luco’s picture

StatusFileSize
new1.81 KB

hi all,

please find an updated patch for D8.9.x.

luco’s picture

StatusFileSize
new1.93 KB

sorry, forgot the comments at the top.

abhijith s’s picture

Patch #13 can't be applied on 9.2.x.Needs reroll.

Checking patch core/modules/node/src/Plugin/Search/NodeSearch.php...
error: while searching for:
    // We need to parse this out into query conditions, some of which go into?
    // the keywords string, and some of which are separate conditions.?
    $parameters = $this->getParameters();?
    if (!empty($parameters['f']) && is_array($parameters['f'])) {?
      $filters = [];?
      // Match any query value that is an expected option and a value?

error: patch failed: core/modules/node/src/Plugin/Search/NodeSearch.php:288
error: core/modules/node/src/Plugin/Search/NodeSearch.php: patch does not apply
abhijith s’s picture

StatusFileSize
new1.78 KB

Rerolled patch #13

Status: Needs review » Needs work

The last submitted patch, 16: 3045362-d9-16.patch, failed testing. View results

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

meenakshi_j’s picture

Status: Needs work » Needs review
StatusFileSize
new5.92 KB
new3.67 KB

Here is the patch which has fixed the fails of #16

adsyy’s picture

#16 is working on 9.2.1

mellowtothemax’s picture

#16 is working on 9.2.10 for me too

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nicrodgers’s picture

StatusFileSize
new5.88 KB

Re-rolled #19 for latest 9.3.x

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gaurav-mathur’s picture

The patch #24 is applied on drupal version 9.5 successfully and this patch also applied on the latest branch and it working fine.
Thankyou

sonam.chaturvedi’s picture

Status: Needs review » Needs work
StatusFileSize
new468.17 KB
new932.76 KB
new796.71 KB

Verified and tested patch #24 on 10.1.x-dev. Patch applied successfully.

Test Results:
1. When no language is chosen in advance-search and normal search, display results only in current language.
2. Issue #5 point 2 (5.2) is reproducible after applying patch

in the normal Search box you will get two keywords 'chocolate chocolate' which gets increase if you put the same in the advance search.

Basically, keyword searched in Advanced-search "Containing any of the words" field is cleared from advance search box and appended to normal search box. And this results in increase of same keywords - "test test".

issue

Moving to Needs Work

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jonnyhocks’s picture

StatusFileSize
new5.91 KB

Re-rolled #24 for latest 10.3.x

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Needs work » Postponed

The Search Module was approved for removal in #3476883: [Policy, no patch] Move Search module to contrib .

This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

The deprecation work is in #3565780: [meta] Tasks to deprecate the Search module and the removal work in #3565783: [meta] Tasks to remove the Search module.

Search will be moved to a contributed project before Drupal 12.0.0 is released.

quietone’s picture

Project: Drupal core » Search (from core)
Version: main » 1.0.0
Component: search.module » Code
Status: Postponed » Needs work

The Search Module has moved from core to contrib,