In this article I described how important the scoring factor settings are in ranking search results. I also demonstrate that it is useful to have the scoring factor controls available directly in the advanced search form. This allows users to decide for every search whether recency, number of comments, page views, or keyword relevance is most important to them. Since these values are only applied at search time, not when the index is created, there is no performance overhead for exposing this feature. If the user doesn't choose to use the feature, the administrative defaults are used.

This patch takes the approach of storing the values in the user's session between the two requests, and deleting the session values when the search is actually run. This makes it so that the search URL doesn't become polluted with scoring factor query information, but also makes it so that bookmarking such a search will not capture the scoring factor information. This point is open for debate and I'll be happy to rewrite the code if it is deemed better to have them in the query string (in fact, that is how I initially wrote the code).

The patch is currently rolled against D5, so it will probably need to be re-rolled for D6.

CommentFileSizeAuthor
advanced-search.patch5.64 KBrobertDouglass
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dmitrig01’s picture

Well, we would need an admin setting

Steven’s picture

Hmm, I think we should consider encoding them in the URL. This could be done using a score:1,2,3,4 syntax or something. This is how the other search stuff works at the moment. The only problem there is again the conflict between the form controls and the text box. It's a hairy problem.

The tricky part is that for some things (like phrases or or), there is no reverse mapping from an arbitrary query string back to the controls. So, we have to clear these boxes after inserting the result in to the keyword box.

However, for terms and type restrictions, we could really remove these from the text box and fill out the form options correctly. The same could be done for the search results. This would keep the URLs clean and readable, while keeping the form as usable as possible.

Of course this could be considered a bit outside of the scope of this patch, but as we pile on more search features, this rapidly becomes an issue. Any takers?

I'm also thinking it should be styled better/more compact. Maybe even some jQuery slider magic like MSN search had at one point.

Dries’s picture

Personally, I'm not convinced that we want to add this functionality. Do we really have to expose this level of control (and internal details) to the user? Shouldn't the search "just work"?

In general, I'm +1 for advanced filters (like we have now) but -1 for controls that manipulate the order of the search results.

What the article tells me is that we might want to change the default scores.

Steven’s picture

Dries: yes, it is a bit of cruft, but on the other hand, this isn't that much of a change. It's just some numbers internally that change. With the right UI (e.g. sliders) and the right search data set, this can be a very useful feature.

Hacking it in via a module is kind of hard, because the node search is not extensible that way. These weights appear in the SQL query that calculates scoring... it woud be piling abstraction layer upon layer upon layer already, and too much would slow down performance or result in insanely complicated UIs. If we had a more robust query builder in core, this would be different, but that's no reason to work on this today.

Improving the default set of rankings is a different issue and in fact applies to all scoring factors in search module. The weights given HTML tags are purely arbitrary for example and based only on intuition and minimal testing.

For me, this can go in, provided it is improved as suggested.

robertDouglass’s picture

I would suggest that (as a separate issue) we boost the keyword relevancy to 7 or 8 by default.

Steven, do you have a slider that I should use?

yan’s picture

I definitely want to support the idea of this issue. Beeing able to control the output of search results in my opinion is really important for users. Maybe not for all of them, but when I visit a website that doesn't offer this option, I like it less.

Dries’s picture

Version: 6.x-dev » 7.x-dev

Moving to D7.

coupet’s picture

We could try the following:

Sort search results (descending to ascending, or vice-versa) by clicking on the currently selected column header. as follows:

Relevance, Activity, Rank, Date published, Latest Comments, # of Comments

birdmanx35’s picture

Status: Needs review » Needs work

No surprises here, but this fails against Drupal HEAD:

$ patch -p0 < advanced-search.patch
patching file modules/node/node.module
Hunk #1 succeeded at 1219 with fuzz 2 (offset 352 lines).
Hunk #2 FAILED at 1240.
Hunk #3 succeeded at 1875 (offset -663 lines).
Hunk #4 succeeded at 1932 with fuzz 2 (offset -663 lines).
1 out of 4 hunks FAILED -- saving rejects to file modules/node/node.module.rej

douggreen’s picture

LIVE FROM THE MINNESOTA SEARCH SPRINT, I agree that some minimal UI for sorting within a results set would be helpful. This needs to be re-rolled, but should wait until #145242 is committed.

alexanderpas’s picture

geerlingguy’s picture

I patched—ahem—'hacked'—Drupal core to rank results by Date. This is something that, imo, should be a link that a user has exposed on the default search page... along with other options for sorting.

You could just have a block that an admin could enable for the search page with the following:

Sort search results by:
-keyword
-date
-number of comments
-etc.

Heck, you could even have the options be in a checklist, so the admin can choose which sorting rules are allowed. This would improve Drupal's search results a ton.

Another +1 if you can let the administrator choose the default sort by date...

yan’s picture

Another +1 if you can let the administrator choose the default sort by date...

Actually that already is implemented: Just go to admin/settings/search and you can change the priority where it says:

The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.

This discussion here is about exposing these settings to the user.

geerlingguy’s picture

Yan - true, but it would be nice to also have the ability to set the default sort by date (maybe adding that as one of the sortable options with a weight in the admin interface).

geerlingguy’s picture

Yan - true, but it would be nice to also have the ability to set the default sort by date (maybe adding that as one of the sortable options with a weight in the admin interface).

yan’s picture

geerlingguy, don't you see the three options "Keyword relevance", "Recently posted", and "Number of comments" there? Just set "Recently posted" to 10 and the other two to 0 and the search results should appear sorted by date (descending). The settings are very limited but at least basic options are available.

geerlingguy’s picture

@ yan - I had that set, but it still didn't sort by date first, then other rankings... I had to modify node.module to add a sort to the search, and even then, it's not easily configured (except by me). If, during the search, there was a "Sort by Date" link somewhere near the top, that would be quite nice.

sun.core’s picture

Version: 7.x-dev » 8.x-dev
jhodgdon’s picture

Component: node.module » search.module

I'm moving this to the search queue, since it's a search feature (and yes I realize it's currently in the node module, and node-search-specific, but I am hoping in Drupal 8 to decouple node.module's search stuff out of node.module and search.module)... we'll see. Anyway, Iam trying to keep all search feature requests together. Hope that is OK.

jhodgdon’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

Since 8.0.x-beta1 has been released, our policy at this point is No feature requests until 8.1.x. See #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?. Sorry, it's just too late for 8.0.x at this point, so even if we had a viable patch, the core committers would not commit it.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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.

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.

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.

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.

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.