forked from e621ng/e621ng
[Posts] Allow excluding multiple ids in search
This commit is contained in:
parent
d9fe9a7602
commit
853790272b
@ -35,15 +35,7 @@ class ElasticPostQueryBuilder < ElasticQueryBuilder
|
||||
must.push({term: {rating: "s"}})
|
||||
end
|
||||
|
||||
if q[:post_id]
|
||||
relation = range_relation(q[:post_id], :id)
|
||||
must.push(relation) if relation
|
||||
end
|
||||
|
||||
if q[:post_id_must_not]
|
||||
must_not.push({ term: { id: q[:post_id_must_not] } })
|
||||
end
|
||||
|
||||
add_array_range_relation(:post_id, :id)
|
||||
add_array_range_relation(:mpixels, :mpixels)
|
||||
add_array_range_relation(:ratio, :aspect_ratio)
|
||||
add_array_range_relation(:width, :width)
|
||||
|
@ -32,8 +32,7 @@ class PostQueryBuilder
|
||||
q = TagQuery.new(query_string)
|
||||
relation = Post.all
|
||||
|
||||
relation = relation.add_range_relation(q[:post_id], "posts.id")
|
||||
relation = add_array_range_relation(relation, q[:mpixels], "posts.image_width * posts.image_height / 1000000.0")
|
||||
relation = add_array_range_relation(relation, q[:post_id], "posts.id")
|
||||
relation = add_array_range_relation(relation, q[:mpixels], "posts.image_width * posts.image_height / 1000000.0")
|
||||
relation = add_array_range_relation(relation, q[:ratio], "ROUND(1.0 * posts.image_width / GREATEST(1, posts.image_height), 2)")
|
||||
relation = add_array_range_relation(relation, q[:width], "posts.image_width")
|
||||
@ -129,10 +128,6 @@ class PostQueryBuilder
|
||||
relation = relation.where("posts.last_noted_at is null")
|
||||
end
|
||||
|
||||
if q[:post_id_must_not]
|
||||
relation = relation.where("posts.id <> ?", q[:post_id_must_not])
|
||||
end
|
||||
|
||||
if q[:parent] == "none"
|
||||
relation = relation.where("posts.parent_id IS NULL")
|
||||
elsif q[:parent] == "any"
|
||||
|
@ -217,11 +217,8 @@ class TagQuery
|
||||
when "statuslocked"
|
||||
add_to_query(parse_boolean(g2) ? :must : :must_not, :locked) { :status }
|
||||
|
||||
when "id"
|
||||
q[:post_id] = ParseValue.range(g2)
|
||||
|
||||
when "-id"
|
||||
q[:post_id_must_not] = g2.to_i
|
||||
when "id", "-id", "~id"
|
||||
add_to_query(type, :post_id) { ParseValue.range(g2) }
|
||||
|
||||
when "width", "-width", "~width"
|
||||
add_to_query(type, :width) { ParseValue.range(g2) }
|
||||
|
@ -17,13 +17,20 @@ class TagQueryTest < ActiveSupport::TestCase
|
||||
should "parse a query" do
|
||||
create(:tag, name: "acb")
|
||||
assert_equal(["abc"], TagQuery.new("md5:abc")[:md5])
|
||||
assert_equal([:between, 1, 2], TagQuery.new("id:1..2")[:post_id])
|
||||
assert_equal([:gt, 2], TagQuery.new("id:>2")[:post_id])
|
||||
assert_equal([:lt, 3], TagQuery.new("id:<3")[:post_id])
|
||||
assert_equal([:lt, 3], TagQuery.new("ID:<3")[:post_id])
|
||||
assert_equal([[:between, 1, 2]], TagQuery.new("id:1..2")[:post_id])
|
||||
assert_equal([[:gt, 2]], TagQuery.new("id:>2")[:post_id])
|
||||
assert_equal([[:lt, 3]], TagQuery.new("id:<3")[:post_id])
|
||||
assert_equal([[:lt, 3]], TagQuery.new("ID:<3")[:post_id])
|
||||
assert_equal(["acb"], TagQuery.new("a*b")[:tags][:should])
|
||||
end
|
||||
|
||||
should "allow multiple types for a metatag in a single query" do
|
||||
query = TagQuery.new("id:1 -id:2 ~id:3 id:4 -id:5 ~id:6")
|
||||
assert_equal([[:eq, 1], [:eq, 4]], query[:post_id])
|
||||
assert_equal([[:eq, 2], [:eq, 5]], query[:post_id_must_not])
|
||||
assert_equal([[:eq, 3], [:eq, 6]], query[:post_id_should])
|
||||
end
|
||||
|
||||
should "fail for more than 40 tags" do
|
||||
assert_raise(TagQuery::CountExceededError) do
|
||||
TagQuery.new("rating:s width:10 height:10 user:bob #{[*'aa'..'zz'].join(' ')}")
|
||||
|
Loading…
Reference in New Issue
Block a user