Limit ApiSearchQuery results to index minimum score (#19407)

This commit is contained in:
Ben Halpern 2023-05-01 17:49:09 -04:00 committed by GitHub
parent 8cf417e4a1
commit bbcd1ed3da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -44,7 +44,10 @@ module Articles
end
def published_articles_with_users_and_organizations
Article.published.includes([{ user: :profile }, :organization]).order(hotness_score: :desc)
Article.published
.includes([{ user: :profile }, :organization])
.where("score >= ?", Settings::UserExperience.index_minimum_score)
.order(hotness_score: :desc)
end
end
end

View file

@ -22,6 +22,13 @@ RSpec.describe Articles::ApiSearchQuery, type: :query do
articles = described_class.call({ q: "ruby" })
expect(articles.count).to eq(1)
end
it "does not show article if below minimum index" do
Settings::UserExperience.index_minimum_score = 10_000
articles = described_class.call({ q: "ruby" })
expect(articles.count).to eq(0)
Settings::UserExperience.index_minimum_score = 0
end
end
context "when there is a top parameter" do