mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: allow consumers to parse a search string (#23528)
This extends search so it can have consumers that: 1. Can split off "term" from various advanced filters and orders 2. Can build a relation of either order or filter It also moves a lot of stuff around in the search class for clarity. Two new APIs are exposed: `.apply_filter` to apply all the special filters to a posts/topics relation `.apply_order` to force a particular order (eg: order:latest) This can then be used by semantic search in Discourse AI
This commit is contained in:
@@ -2748,4 +2748,21 @@ RSpec.describe Search do
|
||||
expect(result.posts.pluck(:id)).to eq([post1.id, post2.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe "Extensibility features of search" do
|
||||
it "is possible to parse queries" do
|
||||
term = "hello l status:closed"
|
||||
search = Search.new(term)
|
||||
|
||||
posts = Post.all.includes(:topic)
|
||||
posts = search.apply_filters(posts)
|
||||
posts = search.apply_order(posts)
|
||||
|
||||
sql = posts.to_sql
|
||||
|
||||
expect(search.term).to eq("hello")
|
||||
expect(sql).to include("ORDER BY posts.created_at DESC")
|
||||
expect(sql).to match(/where.*topics.closed/i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user