bzrudi71 on #2158339-8: Search results page broken on PostgreSQL reported that for Postgres, advanced search does not work.
I just tested in MySQL and it also doesn't work there. Here are the steps to reproduce:
- Clean 8.x install with the Standard install profile.
- Enable Content Translation and Language modules.
- Install a language. I used Spanish.
- Enable translation for the Article content type, and make sure to check the "show language choices on form" box or whatever it's called there. Then go to Manage Fields and edit the settings for Body to make it a translatable field.
- Create a few nodes in English and Spanish. I also made a translation of one of them. Make sure that all nodes and translations in both languages include one shared keyword.
- Run cron to update the search index.
- Go to search/node. Type in your shared keyword. Attempt to filter the search by language. It is not working right.
So in my particular case, I made one just-English node (1), one that has both English and Spanish translations (2), and one just Spanish (3).
When I search for my shared keyword without advanced filters, I end up with the English versions of 1 & 2 and the Spanish 3 shown in the results. The same thing happens no matter what language filters I select. When I filter to just the "Page" content type, that works (none of my three Articles shows up).
Comments
Comment #1
nick_vhBug confirmed, steps to reproduce this are sound and clear. Trying to take a crack at this now.
Comment #2
nick_vhComment #3
nick_vhFound the missing part. The entry as it comes from advanced search is language and not langcode. Changing this makes the behavior work as expected.
Comment #4
nick_vhAlso updated a deprecated function while I was at it. Let's see what the testbot says.
Comment #7
jhodgdonThanks!
We also need a test for this, and one existing test fails with this change.
Comment #8
nick_vhShould fix the test. It was basically sending the langcode as url param while it needed to be language as that is what drupal sends to the URL
Comment #9
nick_vhComment #11
nick_vhComment #12
nick_vhThis should at least apply and succeed
Comment #14
nick_vh11: 2161067-11.patch queued for re-testing.
Comment #15
jhodgdonI haven't tested this patch manually yet, but we also need a test written -- the existing tests did not uncover the fact that the language filter was not working.
So we need to add a new test, demonstrate that it fails without this patch (by uploading a test-only patch), and then demonstrate that it passes with this patch (by uploading a patch with the code changes as well as the new test).
Comment #16
jhodgdonFixing status as per last comment. This definitely needs a test.
Comment #17
chakrapani commentedLooking into this..
Comment #18
chakrapani commentedThe earlier patch #11 does have a change to a test which fails without the fix. Anyways I've added additional tests to check for the search with common keyword in multiple languages. Also checks for no. of results with language filter and checks language of the resulted item.
inter-diff contains the changes from #11 to the PASS patch.
the FAIL patch should FAIL which does not have the fix to the issue.
Lets see what the test-bot has to say.
Comment #20
jhodgdonOK, good job!
So I think we need to step back a moment and think about what the correct result should actually be.
In SearchMultilingualEntityTest, the setUp() creates three English nodes, and it adds a Hungarian "translation" to the second node, and both a Hungarian and 'sv' "translation" to the third node. (For testing purposes, the "translations" are not really in foreign language text -- all 6 of the translations have the word "node" in their title, and randomly-generated body text.)
Anyway, there are only three nodes, but a total of 6 node translations.
So, this test checks that with no language filtering, if we search for the word "node", we get 6 results. I'm just not sure that is what we want, and I think the current behavior without this patch is that we would only get the three base nodes, not multiple translations of the same node. I am just not sure what behavior should be considered "correct" here. We should probably consult with the Multilingual team to figure this out before we decide the issue has been fixed... adding what I hope are correct tags so they'll notice this, and we could also ping people in IRC (but I have to run out now so will check later).
Comment #21
jhodgdonUpon further thought, I think the behavior is correct. The old behavior originally reported in this issue was incorrect, and it was corrected on another issue.
But, we do need another test. The test here is good, but it does not test the UI. We need a test that goes to search/node, chooses a language, submits the form, and verifies that the correct nodes are shown on the page (looking for links to the titles is a good way to do that). A good place to add that might be in SearchLanguageTest, which purports to test language searching but actually doesn't ever check the search results. We'd need to add nodes similar to the test in this patch, but with French, and make sure they're indexed.
Comment #22
chakrapani commentedComment #23
chakrapani commentedHere is the updated patch with additional tests based on suggestion in #21.
interdiff contains changes and it is same for PASS and FAIL patches.
Retained the tests in #18.
Added additional equivalent tests which actually tests UI which include the following:
Comment #25
jhodgdonExcellent! I think this is now ready to go in. I could quibble a bit with grammar in some of the test assert messages, but I think everything is quite readable, so I think we should just get it in.
Comment #26
catchThis is deprecated and will be removed soon, see https://api.drupal.org/api/drupal/core%21modules%21field%21field.depreca...
Comment #27
jhodgdonOK. So it looks like this test that calls field_info_field() instead needs to have
at the top of the file, and then it needs to replace field_info_field(...) with:
chakrapani: would you like to make a new patch? It looks like we should make this change both in the existing SearchMultilingualEntityTest and the new SearchLanguageTest.
Thanks!
Comment #28
chakrapani commented@catch, thanks for the catch :)
@jhodgdon, Yes I will add a new patch.
Comment #29
chakrapani commentedHere we go..Added patches with the suggested change in #26 and #27.
interdiff is same for both FAIL and PASS patch.
Comment #31
jhodgdonThanks, looks right to me, and the tests are passing/failing as they should. Back to RTBC. One less deprecated function in the code base. :)
Comment #32
catchPeriods missing from both these comments but I fixed locally and committed/pushed to 8.x, thanks!