feat: improve article search ranking (#11640)
This commit is contained in:
@@ -76,18 +76,24 @@ class Article < ApplicationRecord
|
||||
scope :order_by_views, -> { reorder(views: :desc) }
|
||||
|
||||
# TODO: if text search slows down https://www.postgresql.org/docs/current/textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS
|
||||
# - the A, B and C are for weightage. See: https://github.com/Casecommons/pg_search#weighting
|
||||
# - the normalization is for ensuring the long articles that mention the search term too many times are not ranked higher.
|
||||
# it divides rank by log(document_length) to prevent longer articles from ranking higher just due to sizeSee: https://github.com/Casecommons/pg_search#normalization
|
||||
# - the ranking is to ensure that articles with higher weightage are ranked higher
|
||||
pg_search_scope(
|
||||
:text_search,
|
||||
against: %i[
|
||||
title
|
||||
description
|
||||
content
|
||||
],
|
||||
against: {
|
||||
title: 'A',
|
||||
description: 'B',
|
||||
content: 'C'
|
||||
},
|
||||
using: {
|
||||
tsearch: {
|
||||
prefix: true
|
||||
prefix: true,
|
||||
normalization: 2
|
||||
}
|
||||
}
|
||||
},
|
||||
ranked_by: ':tsearch'
|
||||
)
|
||||
|
||||
def self.search(params)
|
||||
|
||||
Reference in New Issue
Block a user