Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In views_handler_filter_search.inc the search filter uses $this->query->add_groupby("search_index.sid");
. If your search view uses a sort (mine sorts by search score DESC), then function add_orderby adds the sort into the grouping. This has the effect of preventing multiple word searches from working.
The query ends up like
SELECT node.nid AS nid,
SUM(search_index.score * search_total.count) AS score,
search_index.score AS search_index_score,
search_index.*
FROM node node
LEFT JOIN book book ON node.nid = book.nid
INNER JOIN node node_book ON book.bid = node_book.nid
LEFT JOIN search_index search_index ON node.nid = search_index.sid
LEFT JOIN search_total search_total ON search_index.word = search_total.word
WHERE (node.status <> 0) AND (node.type in ('book')) AND (search_index.word = 'yet' OR search_index.word = 'published') AND (search_index.type = 'node') AND (node_book.nid = 1653)
GROUP BY search_index.sid, search_index_score
HAVING COUNT(*) >= 2
ORDER BY search_index_score ASC
Because my two different words have different search_index_scores, the group by search_index_score prevents the intended results.
If I change the query to just GROUP BY search_index.sid then I get my results.
Comment | File | Size | Author |
---|---|---|---|
#5 | 362830-search-score-totally-broken.patch | 8.36 KB | merlinofchaos |
Comments
Comment #1
kleinmp CreditAttribution: kleinmp commentedI added the following hook into a module and it helped correct this particular search problem:
Comment #2
gagarine CreditAttribution: gagarine commentedI don't use a sort but have the same issue if i search words from two differents fields or taxonomy.
The seach filter are my unique exposed filter.
Comment #3
gagarine CreditAttribution: gagarine commentedComment #4
merlinofchaos CreditAttribution: merlinofchaos commentedThat hack, while clever, only fixes part of the problem. That sort is completely inappropriate; it sorts by the score of each term, not the aggregated score. So it doesn't actually sort at all. And doesn't work on postgres anyway.
Working on a fix; for right now, the workaround is...don't sort on score. :P
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedOk, I believe this patch fixes it. It also fixes the score rendering. It also makes search relationship safe, which it was not previously. This includes the patch from #373760: Views 2 Search Term Exposed Filter does not provide results when searched 2+ multiple words as well, even though they're different bugs they affect the same code so having two different patches is a pain. I'm marking that one a dup and continuing all work on that here.
Comment #6
gagarine CreditAttribution: gagarine commentedI quikly test the patch 362830-search-score-totally-broken.patch but they don't solve my problem. If I search two world from two different field i have no result.
Comment #7
merlinofchaos CreditAttribution: merlinofchaos commentedgagarine: Wow, can you be any less descriptive? How about you actually use reasonably troubleshooting and analysis rather than shooting down hours of my work without saying anything of value?
Comment #8
kleinmp CreditAttribution: kleinmp commentedI tried out the patch and it worked nicely :) Thanks!
Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedOk, I identified a couple of interaction problems with the patch. Particularly when using tables and table sort. I think I have it all worked out, and it worked in every situation I tested, so I went ahead and committed it.
If you're having a problem with this continuing to not work after getting the newest code, be sure to include your exact view setup and paste a query to demonstrate it not working.
Comment #10
dwwNote, I ported the project issue advanced search views to use this functionality and deployed it on d.o. For example:
http://drupal.org/project/issues/search?text=stale
Seems to be working fine. If there are any problems, I'm sure the d.o user-base will flesh them out. ;)
Thanks, Earl!
-Derek
Comment #12
xsean CreditAttribution: xsean commentedhi,
i still got this problem where there are no result when i try search multiple word or special character like (, ), - and it not include in the query. when i use core search, there are record found but not with views search-term.
below is my query:
SELECT node.nid AS nid,
SUM(search_index.score * search_total.count) AS score,
node.title AS node_title,
node.type AS node_type,
node_revisions.body AS node_revisions_body,
node_revisions.format AS node_revisions_format,
node_data_field_features.field_features_value AS node_data_field_features_field_features_value,
RAND() AS _random
FROM node node
LEFT JOIN search_index search_index ON node.nid = search_index.sid
LEFT JOIN search_total search_total ON search_index.word = search_total.word
LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
LEFT JOIN content_field_features node_data_field_features ON node.vid = node_data_field_features.vid
WHERE (node.type in ('dining_directory', 'hotels_directory')) AND (node.status <> 0) AND (search_index.word = 'address' OR search_index.word = '123') AND (search_index.type = 'node')
GROUP BY search_index.sid, node_data_field_features_field_features_value, nid, node_title, node_type, node_revisions_body, node_revisions_format, _random
HAVING COUNT(*) >= 2
ORDER BY node_data_field_features_field_features_value ASC, _random ASC
i tried to update with patch but seem the latest version 6x-2.8 already include from the patch.
i'm very appreciate if anyone can let me know what's the problem? all i want the search term can search by multiple word or is good can search using 'LIKE' instead of 'OR'
thanks
Comment #13
franzSame issue here. The GROUP BY _random causes the results to be null. Removing it on the query solves the issue.
Not sure about how to fix this on code.
Comment #14
dawehner@Franz
Did you tryed the latest version of views and cck?
Comment #15
esmerel CreditAttribution: esmerel commentedIF this is still a problem against the most recent release, open a new issue against that release.