Search Improvements in 2.3

For the upcoming 2.3 release, we’ve added a new feature and made several fixes to the way we index posts for search that will make search results better.

1. Search Priorities for Categories


Each individual category can be configured with a search priority which you can find under the Settings tab when creating/editing a category. Five levels for prioritization have been added: ignore, very low, low, high and very high. The levels work by multiplying a pre-configured weight to the search ranking for each result and can be configured via hidden site settings in your console.

https://github.com/discourse/discourse/blob/588f61f717d59d0ac2030f290b98145a7a5956d1/config/site_settings.yml#L1618-L1633

As an example, configuring a category’s search priority to very_high will boost its search ranking by 40% while a search priority of very_low will reduce its search ranking by 40%. Setting a category’s search priority to ignore will remove it from the search results. However, you can still search for posts within the ignored category by scoping the search to the category via advanced search. Do take note that search priority is not inherited which means that a sub-category will still be searchable even if the parent category has been configured to be ignored.

2. Improvements and Fixes to Search Results

  1. Search relevance has been updated to consider the document length in the ranking. Previously, search ranking was ranked by the most number of matches for the given search term. This was problematic for search results as we noticed that longer posts were more likely to be ranked higher because of the tendency to produce a higher number of matches. As a result, we’ve made the switch to consider the document length when ranking search results.
    https://github.com/discourse/discourse/commit/e87ca594014733d171df0112149f49180d898678

  2. Improve the quality of the raw data that we use to generate the search index. https://github.com/discourse/discourse/commit/cfd507822f9330967f3ed9f970505e7f4896b523

    • URLs in posts were sometimes incorrectly tokenized and indexed twice leading to terms within links having a higher ranking.
    • Content for lightboxes in posts were polluting search results with the image’s metadata.
  3. Empty posts such as moderator actions or small post actions (closing, assigning) are no longer part of the search index. This change leads to a smaller index and less noise in search results. https://github.com/discourse/discourse/commit/daeda80ada1d914d52dcc53a2cda087e5f62330c

  4. Smaller search index by deleting posts of trashed topics from the index. https://github.com/discourse/discourse/commit/d151425353cb4a99ee9cc543ed75925d9c3edc17

  5. When a post is moved to a different topic, the search data for the post was not updated and would lead to the post incorrectly appearing in searches that matched the category of the old topic. https://github.com/discourse/discourse/commit/d808f36fc407a201b79755d9e48e7682e8407edd

  6. Smaller payload for search results by excluding the cooked version of the posts. https://github.com/discourse/discourse/commit/03c6b22c626c6c91e009020e40817751d1421324

  7. The blurb for posts in search results was broken when searching for an exact phrase and lead to missing search term highlights on the client side. https://github.com/discourse/discourse/commit/dae0bb4c67c9f7f1eb475fb60f375118f93cdfd9

Do let us know if you’re search results have improved after these changes. We would also like to know if you think your search results have become worse so that we can continue to refine it. Thank you all!

43 Likes

Is the age of a post part of the weight in ranking search results? Information gets stale fairly quickly in our forum, so it would be nice to have a way to reduce the relevance of older postings without actually eliminating them.

11 Likes

Not yet, but it is an interesting idea, even in the weaker form of simply factoring in the date the topic was last touched

7 Likes

I would love to see a way to “pin” topics in search results so they appear first. That way common searches things can be lead directly to our tutorials.

You do this by changing search priority for the category those topics are in.

My “issue” is that those topics are spread through all forum categories on contextual basis. Hence I can’t use the category-based approach.

Then you are stuck because there is no random per topic way to do this, and there never will be.

Maybe search priorities for tags could be a thing eventually? Although not as straight forward since topics can have multiple tags…

Being able to weight categories is a great feature anyway! I already have several spammy special-use categories on my forum that will be nice to push down a bit in search.

6 Likes

Yes, I see this happening at some point.

10 Likes

That would be awesome! That way blog posts can be tagged as such and prioritized for search…

1 Like

I would love to see a way for certain tags to affect the search priority also.

4 Likes

Is there any plan to add this to 2.4.X? or 2.5?

Is this a thing now?

I am not savvy enough to decipher this resource: Search Controller Need help with understanding how discourse search works - #3 by neounix

2 Likes

Not yet. At the moment only categories have a configurable search prioritization.

3 Likes