Merge pull request #4917 from dmacjam/search_posts_with_images
Search posts with images
This commit is contained in:
commit
057a69a55d
|
@ -10,13 +10,13 @@ const REGEXP_CATEGORY_PREFIX = /^(category:|#)/ig;
|
||||||
const REGEXP_GROUP_PREFIX = /^group:/ig;
|
const REGEXP_GROUP_PREFIX = /^group:/ig;
|
||||||
const REGEXP_BADGE_PREFIX = /^badge:/ig;
|
const REGEXP_BADGE_PREFIX = /^badge:/ig;
|
||||||
const REGEXP_TAGS_PREFIX = /^(tags?:|#(?=[a-z0-9\-]+::tag))/ig;
|
const REGEXP_TAGS_PREFIX = /^(tags?:|#(?=[a-z0-9\-]+::tag))/ig;
|
||||||
const REGEXP_IN_PREFIX = /^in:/ig;
|
const REGEXP_IN_PREFIX = /^(in|with):/ig;
|
||||||
const REGEXP_STATUS_PREFIX = /^status:/ig;
|
const REGEXP_STATUS_PREFIX = /^status:/ig;
|
||||||
const REGEXP_MIN_POST_COUNT_PREFIX = /^min_post_count:/ig;
|
const REGEXP_MIN_POST_COUNT_PREFIX = /^min_post_count:/ig;
|
||||||
const REGEXP_POST_TIME_PREFIX = /^(before|after):/ig;
|
const REGEXP_POST_TIME_PREFIX = /^(before|after):/ig;
|
||||||
const REGEXP_TAGS_REPLACE = /(^(tags?:|#(?=[a-z0-9\-]+::tag))|::tag\s?$)/ig;
|
const REGEXP_TAGS_REPLACE = /(^(tags?:|#(?=[a-z0-9\-]+::tag))|::tag\s?$)/ig;
|
||||||
|
|
||||||
const REGEXP_IN_MATCH = /^in:(posted|watching|tracking|bookmarks|first|pinned|unpinned|wiki|unseen)/ig;
|
const REGEXP_IN_MATCH = /^(in|with):(posted|watching|tracking|bookmarks|first|pinned|unpinned|wiki|unseen|image)/ig;
|
||||||
const REGEXP_SPECIAL_IN_LIKES_MATCH = /^in:likes/ig;
|
const REGEXP_SPECIAL_IN_LIKES_MATCH = /^in:likes/ig;
|
||||||
const REGEXP_SPECIAL_IN_PRIVATE_MATCH = /^in:private/ig;
|
const REGEXP_SPECIAL_IN_PRIVATE_MATCH = /^in:private/ig;
|
||||||
const REGEXP_SPECIAL_IN_SEEN_MATCH = /^in:seen/ig;
|
const REGEXP_SPECIAL_IN_SEEN_MATCH = /^in:seen/ig;
|
||||||
|
@ -25,6 +25,8 @@ const REGEXP_CATEGORY_SLUG = /^(\#[a-zA-Z0-9\-:]+)/ig;
|
||||||
const REGEXP_CATEGORY_ID = /^(category:[0-9]+)/ig;
|
const REGEXP_CATEGORY_ID = /^(category:[0-9]+)/ig;
|
||||||
const REGEXP_POST_TIME_WHEN = /^(before|after)/ig;
|
const REGEXP_POST_TIME_WHEN = /^(before|after)/ig;
|
||||||
|
|
||||||
|
const IN_OPTIONS_MAPPING = {'images': 'with'};
|
||||||
|
|
||||||
export default Em.Component.extend({
|
export default Em.Component.extend({
|
||||||
classNames: ['search-advanced-options'],
|
classNames: ['search-advanced-options'],
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ export default Em.Component.extend({
|
||||||
{name: I18n.t('search.advanced.filters.pinned'), value: "pinned"},
|
{name: I18n.t('search.advanced.filters.pinned'), value: "pinned"},
|
||||||
{name: I18n.t('search.advanced.filters.unpinned'), value: "unpinned"},
|
{name: I18n.t('search.advanced.filters.unpinned'), value: "unpinned"},
|
||||||
{name: I18n.t('search.advanced.filters.wiki'), value: "wiki"},
|
{name: I18n.t('search.advanced.filters.wiki'), value: "wiki"},
|
||||||
|
{name: I18n.t('search.advanced.filters.images'), value: "images"},
|
||||||
],
|
],
|
||||||
statusOptions: [
|
statusOptions: [
|
||||||
{name: I18n.t('search.advanced.statuses.open'), value: "open"},
|
{name: I18n.t('search.advanced.statuses.open'), value: "open"},
|
||||||
|
@ -398,13 +401,17 @@ export default Em.Component.extend({
|
||||||
updateSearchTermForIn() {
|
updateSearchTermForIn() {
|
||||||
const match = this.filterBlocks(REGEXP_IN_MATCH);
|
const match = this.filterBlocks(REGEXP_IN_MATCH);
|
||||||
const inFilter = this.get('searchedTerms.in');
|
const inFilter = this.get('searchedTerms.in');
|
||||||
|
let keyword = 'in';
|
||||||
|
if(inFilter in IN_OPTIONS_MAPPING) {
|
||||||
|
keyword = IN_OPTIONS_MAPPING[inFilter];
|
||||||
|
}
|
||||||
let searchTerm = this.get('searchTerm') || '';
|
let searchTerm = this.get('searchTerm') || '';
|
||||||
|
|
||||||
if (inFilter) {
|
if (inFilter) {
|
||||||
if (match.length !== 0) {
|
if (match.length !== 0) {
|
||||||
searchTerm = searchTerm.replace(match[0], `in:${inFilter}`);
|
searchTerm = searchTerm.replace(match[0], `${keyword}:${inFilter}`);
|
||||||
} else {
|
} else {
|
||||||
searchTerm += ` in:${inFilter}`;
|
searchTerm += ` ${keyword}:${inFilter}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('searchTerm', searchTerm.trim());
|
this.set('searchTerm', searchTerm.trim());
|
||||||
|
|
|
@ -1374,6 +1374,7 @@ en:
|
||||||
seen: I've read
|
seen: I've read
|
||||||
unseen: I've not read
|
unseen: I've not read
|
||||||
wiki: are wiki
|
wiki: are wiki
|
||||||
|
images: includes image(s)
|
||||||
all_tags: Contains all tags
|
all_tags: Contains all tags
|
||||||
statuses:
|
statuses:
|
||||||
label: Where topics
|
label: Where topics
|
||||||
|
|
|
@ -80,8 +80,6 @@ class CookedPostProcessor
|
||||||
limit_size!(img)
|
limit_size!(img)
|
||||||
convert_to_link!(img)
|
convert_to_link!(img)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_post_image
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_images
|
def extract_images
|
||||||
|
@ -102,8 +100,6 @@ class CookedPostProcessor
|
||||||
@doc.css("img[src]") -
|
@doc.css("img[src]") -
|
||||||
# minus, emojis
|
# minus, emojis
|
||||||
@doc.css("img.emoji") -
|
@doc.css("img.emoji") -
|
||||||
# minus, image inside oneboxes
|
|
||||||
oneboxed_images -
|
|
||||||
# minus, images inside quotes
|
# minus, images inside quotes
|
||||||
@doc.css(".quote img")
|
@doc.css(".quote img")
|
||||||
end
|
end
|
||||||
|
@ -292,6 +288,8 @@ class CookedPostProcessor
|
||||||
|
|
||||||
def update_post_image
|
def update_post_image
|
||||||
img = extract_images_for_post.first
|
img = extract_images_for_post.first
|
||||||
|
return if img.blank?
|
||||||
|
|
||||||
if img["src"].present?
|
if img["src"].present?
|
||||||
@post.update_column(:image_url, img["src"][0...255]) # post
|
@post.update_column(:image_url, img["src"][0...255]) # post
|
||||||
@post.topic.update_column(:image_url, img["src"][0...255]) if @post.is_first_post? # topic
|
@post.topic.update_column(:image_url, img["src"][0...255]) if @post.is_first_post? # topic
|
||||||
|
@ -310,6 +308,11 @@ class CookedPostProcessor
|
||||||
Oneboxer.onebox(url, args)
|
Oneboxer.onebox(url, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
update_post_image
|
||||||
|
|
||||||
|
# make sure we grab dimensions for oneboxed images
|
||||||
|
oneboxed_images.each { |img| limit_size!(img) }
|
||||||
|
|
||||||
uploads = oneboxed_image_uploads.select(:url, :origin)
|
uploads = oneboxed_image_uploads.select(:url, :origin)
|
||||||
oneboxed_images.each do |img|
|
oneboxed_images.each do |img|
|
||||||
upload = uploads.detect { |u| u.origin == img["src"] }
|
upload = uploads.detect { |u| u.origin == img["src"] }
|
||||||
|
|
|
@ -357,6 +357,10 @@ class Search
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
advanced_filter(/with:images/) do |posts|
|
||||||
|
posts.where("posts.image_url IS NOT NULL")
|
||||||
|
end
|
||||||
|
|
||||||
advanced_filter(/category:(.+)/) do |posts, match|
|
advanced_filter(/category:(.+)/) do |posts, match|
|
||||||
exact = false
|
exact = false
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ describe CookedPostProcessor do
|
||||||
it "adds a topic image if there's one in the first post" do
|
it "adds a topic image if there's one in the first post" do
|
||||||
FastImage.stubs(:size)
|
FastImage.stubs(:size)
|
||||||
expect(post.topic.image_url).to eq(nil)
|
expect(post.topic.image_url).to eq(nil)
|
||||||
cpp.post_process_images
|
cpp.update_post_image
|
||||||
post.topic.reload
|
post.topic.reload
|
||||||
expect(post.topic.image_url).to be_present
|
expect(post.topic.image_url).to be_present
|
||||||
end
|
end
|
||||||
|
@ -262,7 +262,7 @@ describe CookedPostProcessor do
|
||||||
it "adds a post image if there's one in the post" do
|
it "adds a post image if there's one in the post" do
|
||||||
FastImage.stubs(:size)
|
FastImage.stubs(:size)
|
||||||
expect(reply.image_url).to eq(nil)
|
expect(reply.image_url).to eq(nil)
|
||||||
cpp.post_process_images
|
cpp.update_post_image
|
||||||
reply.reload
|
reply.reload
|
||||||
expect(reply.image_url).to be_present
|
expect(reply.image_url).to be_present
|
||||||
end
|
end
|
||||||
|
|
|
@ -632,6 +632,17 @@ describe Search do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'can find posts with images' do
|
||||||
|
post_uploaded = Fabricate(:post_with_uploaded_image)
|
||||||
|
post_with_image_urls = Fabricate(:post_with_image_urls)
|
||||||
|
Fabricate(:post)
|
||||||
|
|
||||||
|
CookedPostProcessor.new(post_uploaded).update_post_image
|
||||||
|
CookedPostProcessor.new(post_with_image_urls).update_post_image
|
||||||
|
|
||||||
|
expect(Search.execute('with:images').posts.map(&:id)).to contain_exactly(post_uploaded.id, post_with_image_urls.id)
|
||||||
|
end
|
||||||
|
|
||||||
it 'can find by latest' do
|
it 'can find by latest' do
|
||||||
topic1 = Fabricate(:topic, title: 'I do not like that Sam I am')
|
topic1 = Fabricate(:topic, title: 'I do not like that Sam I am')
|
||||||
post1 = Fabricate(:post, topic: topic1)
|
post1 = Fabricate(:post, topic: topic1)
|
||||||
|
|
Loading…
Reference in New Issue