Hello,
I have installation of Drupal 8.4.4 and Views 8.4.4.
I have configured a view to show my search results with a random sorting.
But the random sort is not applied, results only show up in order of date creation.
I have read this thread https://www.drupal.org/project/search_api/issues/1197538 wich at some point fixed the problem.
Can someone reproduce the bug ?
Thanks in advance for your help !
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2944371-16--db_backend_random_sort.patch | 5.33 KB | drunken monkey |
Comments
Comment #2
drunken monkeyWhich server backend are you using, Solr, database or something else?
Comment #3
jasonschweb commentedI need random DB sort for project I'm working on for Database backend, so I created this patch which works with either the standard random sort OR views_random_seed using the following patch: https://www.drupal.org/files/issues/views_random_seed_search_api.patch from here: https://www.drupal.org/project/views_random_seed/issues/2939507
views_random_seed is not required but the attached patch will only work on mysql. Hopefully this is a good starting point for getting this feature added to the module.
Comment #4
kbeck303 commentedI have tested this patch (views sort using global: random field) and it works running core 8.5.5 and search_api 1.8, I also have search_api_sorts beta1 installed.
Comment #5
drunken monkeyThanks a lot for the patch! That's a good start. Several things still need to be addressed, though:
DatabaseCompatibilityclasses (\Drupal\search_api_db\DatabaseCompatibility\GenericDatabaseet al.).Comment #6
drunken monkeyComment #7
basvredelingPatch #3 is still relevant on D8.7.10
Comment #8
pyxio commentedpatch does not work for drupal 8.8.1
Comment #9
amccune commentedI was able to apply the patch manually in core 8.8.6 and search_api 8.x-1.16. Working great.
Comment #10
upchuk commentedAlright, took a stab at this, @drunken monkey. I don't have experience with Postgres and SQLite so maybe someone can help with that.
I also moved things to the
DatabaseCompatibilityclasses (hope it's what you meant) and wrote a test.Changed also the status to Feature request as it was simply something that was not covered, not a bug per se.
Comment #13
upchuk commentedAh, seems I missed the whole "partial" search configuration, corrected the patches. However, I do see the tests here run with SQLite so in the CI they might not work. Locally with Mysql it works.
Comment #16
drunken monkeyThanks a lot for your work on this, great job! Yes, moving this code to the
DatabaseCompatibilityclasses was exactly what I meant.I also verified that it works with MySQL, but supporting SQLite and Postgres, too, shouldn’t actually be too hard. Patch attached, please test/review.
(Also moved the
$this->searchWithRandom()call to the region where partial search isn’t enabled. Why complicate it with that?)Comment #17
upchuk commentedLooks good to me. I see you added something to the Generic class, I believe that covers SQLLite. I see postgres also seem to use random() for the expression. So it's ok I guess? Test is green so clearly it works for SQLLite.
I'm not gonna RTBC as it's my initial patch, I guess someone else can take a look?
Comment #19
drunken monkeyTests passing for all three environments and you giving your OK is good enough for me. (Especially since no-one else wanted to review over the last month.)
So: committed.
Thanks a lot again, everyone!