Fix tag related advanced search tests into one context. Fix dynamic locale and select clause in search by all tags. Fix separator for all tags to plus sign.
This commit is contained in:
parent
3eebcccbf2
commit
eaec35d230
|
@ -234,7 +234,7 @@ export default Em.Component.extend({
|
||||||
const contain_all_tags = this.get('searchedTerms.special.all_tags');
|
const contain_all_tags = this.get('searchedTerms.special.all_tags');
|
||||||
|
|
||||||
if (match.length !== 0) {
|
if (match.length !== 0) {
|
||||||
const join_char = contain_all_tags ? ',' : '|';
|
const join_char = contain_all_tags ? '+' : ',';
|
||||||
const existingInput = _.isArray(tags) ? tags.join(join_char) : tags;
|
const existingInput = _.isArray(tags) ? tags.join(join_char) : tags;
|
||||||
const userInput = match[0].replace(REGEXP_TAGS_REPLACE, '');
|
const userInput = match[0].replace(REGEXP_TAGS_REPLACE, '');
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ export default Em.Component.extend({
|
||||||
const contain_all_tags = this.get('searchedTerms.special.all_tags');
|
const contain_all_tags = this.get('searchedTerms.special.all_tags');
|
||||||
|
|
||||||
if (tagFilter && tagFilter.length !== 0) {
|
if (tagFilter && tagFilter.length !== 0) {
|
||||||
const join_char = contain_all_tags ? ',' : '|';
|
const join_char = contain_all_tags ? '+' : ',';
|
||||||
const tags = tagFilter.join(join_char);
|
const tags = tagFilter.join(join_char);
|
||||||
|
|
||||||
if (match.length !== 0) {
|
if (match.length !== 0) {
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="container">contain_all_tags
|
<div class="container">
|
||||||
<div class="control-group pull-left">
|
<div class="control-group pull-left">
|
||||||
<label class="control-label" for="search-in-options">{{i18n "search.advanced.filters.label"}}</label>
|
<label class="control-label" for="search-in-options">{{i18n "search.advanced.filters.label"}}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
|
@ -445,20 +445,19 @@ class Search
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
advanced_filter(/tags?:([a-zA-Z0-9,\-_|]+)/) do |posts, match|
|
advanced_filter(/tags?:([a-zA-Z0-9,\-_+]+)/) do |posts, match|
|
||||||
if match.include?(',')
|
if match.include?('+')
|
||||||
tags = match.split(",")
|
tags = match.split('+')
|
||||||
|
|
||||||
# TODO use ts_query function
|
|
||||||
posts.where("topics.id IN (
|
posts.where("topics.id IN (
|
||||||
SELECT DISTINCT(tt.topic_id)
|
SELECT tt.topic_id
|
||||||
FROM topic_tags tt, tags
|
FROM topic_tags tt, tags
|
||||||
WHERE tt.tag_id = tags.id
|
WHERE tt.tag_id = tags.id
|
||||||
GROUP BY tt.topic_id
|
GROUP BY tt.topic_id
|
||||||
HAVING to_tsvector('simple',array_to_string(array_agg(tags.name), ' ')) @@ to_tsquery('simple', ?)
|
HAVING to_tsvector(#{query_locale}, array_to_string(array_agg(tags.name), ' ')) @@ to_tsquery(#{query_locale}, ?)
|
||||||
)", tags.join('&'))
|
)", tags.join('&'))
|
||||||
else
|
else
|
||||||
tags = match.split("|")
|
tags = match.split(",")
|
||||||
|
|
||||||
posts.where("topics.id IN (
|
posts.where("topics.id IN (
|
||||||
SELECT DISTINCT(tt.topic_id)
|
SELECT DISTINCT(tt.topic_id)
|
||||||
|
|
|
@ -694,34 +694,32 @@ describe Search do
|
||||||
expect(Search.execute('this is a test #beta').posts.size).to eq(0)
|
expect(Search.execute('this is a test #beta').posts.size).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can find with tag" do
|
|
||||||
topic1 = Fabricate(:topic, title: 'Could not, would not, on a boat')
|
|
||||||
topic1.tags = [Fabricate(:tag, name: 'eggs'), Fabricate(:tag, name: 'ham')]
|
|
||||||
Fabricate(:post, topic: topic1)
|
|
||||||
post2 = Fabricate(:post, topic: topic1, raw: "It probably doesn't help that they're green...")
|
|
||||||
|
|
||||||
expect(Search.execute('green tags:eggs').posts.map(&:id)).to eq([post2.id])
|
|
||||||
expect(Search.execute('green tags:plants').posts.size).to eq(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'tags' do
|
context 'tags' do
|
||||||
let(:tag1) { Fabricate(:tag, name: 'lunch') }
|
let(:tag1) { Fabricate(:tag, name: 'lunch') }
|
||||||
let(:tag2) { Fabricate(:tag, name: 'eggs') }
|
let(:tag2) { Fabricate(:tag, name: 'eggs') }
|
||||||
let(:topic1) { Fabricate(:topic, tags: [tag2, Fabricate(:tag)]) }
|
let(:topic1) { Fabricate(:topic, tags: [tag2, Fabricate(:tag)]) }
|
||||||
let(:topic2) { Fabricate(:topic, tags: [tag1]) }
|
let(:topic2) { Fabricate(:topic, tags: [tag2]) }
|
||||||
let(:topic3) { Fabricate(:topic, tags: [tag1, tag2]) }
|
let(:topic3) { Fabricate(:topic, tags: [tag1, tag2]) }
|
||||||
let!(:post1) { Fabricate(:post, topic: topic1)}
|
let!(:post1) { Fabricate(:post, topic: topic1)}
|
||||||
let!(:post2) { Fabricate(:post, topic: topic2)}
|
let!(:post2) { Fabricate(:post, topic: topic2)}
|
||||||
let!(:post3) { Fabricate(:post, topic: topic3)}
|
let!(:post3) { Fabricate(:post, topic: topic3)}
|
||||||
|
|
||||||
|
it 'can find posts with tag' do
|
||||||
|
post4 = Fabricate(:post, topic: topic3, raw: "It probably doesn't help that they're green...")
|
||||||
|
|
||||||
|
expect(Search.execute('green tags:eggs').posts.map(&:id)).to eq([post4.id])
|
||||||
|
expect(Search.execute('tags:plants').posts.size).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
it 'can find posts with any tag from multiple tags' do
|
it 'can find posts with any tag from multiple tags' do
|
||||||
Fabricate(:post)
|
Fabricate(:post)
|
||||||
|
|
||||||
expect(Search.execute('tags:eggs|lunch').posts.map(&:id).sort).to eq([post1.id, post2.id, post3.id].sort)
|
expect(Search.execute('tags:eggs,lunch').posts.map(&:id).sort).to eq([post1.id, post2.id, post3.id].sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can find posts which contains all provided tags' do
|
it 'can find posts which contains all provided tags' do
|
||||||
expect(Search.execute('tags:lunch,eggs').posts.map(&:id)).to eq([post3.id])
|
expect(Search.execute('tags:lunch+eggs').posts.map(&:id)).to eq([post3.id])
|
||||||
|
expect(Search.execute('tags:eggs+lunch').posts.map(&:id)).to eq([post3.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue