Add extraction of image_url for oneboxed images. Fix search by images filter name.

This commit is contained in:
Jakub Macina 2017-06-09 13:16:50 +02:00
parent 76712da166
commit bf002e0873
5 changed files with 19 additions and 13 deletions

View File

@ -8,13 +8,13 @@ const REGEXP_CATEGORY_PREFIX = /^(category:|#)/ig;
const REGEXP_GROUP_PREFIX = /^group:/ig;
const REGEXP_BADGE_PREFIX = /^badge:/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_MIN_POST_COUNT_PREFIX = /^min_post_count:/ig;
const REGEXP_POST_TIME_PREFIX = /^(before|after):/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|image)/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_PRIVATE_MATCH = /^in:private/ig;
const REGEXP_SPECIAL_IN_SEEN_MATCH = /^in:seen/ig;
@ -23,6 +23,8 @@ const REGEXP_CATEGORY_SLUG = /^(\#[a-zA-Z0-9\-:]+)/ig;
const REGEXP_CATEGORY_ID = /^(category:[0-9]+)/ig;
const REGEXP_POST_TIME_WHEN = /^(before|after)/ig;
const IN_OPTIONS_MAPPING = {'images': 'with'};
export default Em.Component.extend({
classNames: ['search-advanced-options'],
@ -36,7 +38,7 @@ export default Em.Component.extend({
{name: I18n.t('search.advanced.filters.pinned'), value: "pinned"},
{name: I18n.t('search.advanced.filters.unpinned'), value: "unpinned"},
{name: I18n.t('search.advanced.filters.wiki'), value: "wiki"},
{name: I18n.t('search.advanced.filters.images'), value: "image"},
{name: I18n.t('search.advanced.filters.images'), value: "images"},
],
statusOptions: [
{name: I18n.t('search.advanced.statuses.open'), value: "open"},
@ -392,13 +394,17 @@ export default Em.Component.extend({
updateSearchTermForIn() {
const match = this.filterBlocks(REGEXP_IN_MATCH);
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') || '';
if (inFilter) {
if (match.length !== 0) {
searchTerm = searchTerm.replace(match[0], `in:${inFilter}`);
searchTerm = searchTerm.replace(match[0], `${keyword}:${inFilter}`);
} else {
searchTerm += ` in:${inFilter}`;
searchTerm += ` ${keyword}:${inFilter}`;
}
this.set('searchTerm', searchTerm.trim());

View File

@ -76,8 +76,6 @@ class CookedPostProcessor
limit_size!(img)
convert_to_link!(img)
end
update_post_image
end
def extract_images
@ -98,8 +96,6 @@ class CookedPostProcessor
@doc.css("img[src]") -
# minus, emojis
@doc.css("img.emoji") -
# minus, image inside oneboxes
oneboxed_images -
# minus, images inside quotes
@doc.css(".quote img")
end
@ -283,6 +279,8 @@ class CookedPostProcessor
def update_post_image
img = extract_images_for_post.first
return if img.blank?
if img["src"].present?
@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
@ -301,6 +299,8 @@ class CookedPostProcessor
Oneboxer.onebox(url, args)
end
update_post_image
# make sure we grab dimensions for oneboxed images
oneboxed_images.each { |img| limit_size!(img) }

View File

@ -338,7 +338,7 @@ class Search
end
end
advanced_filter(/in:image/) do |posts|
advanced_filter(/with:images/) do |posts|
posts.where("posts.image_url IS NOT NULL")
end

View File

@ -249,7 +249,7 @@ describe CookedPostProcessor do
it "adds a topic image if there's one in the first post" do
FastImage.stubs(:size)
expect(post.topic.image_url).to eq(nil)
cpp.post_process_images
cpp.update_post_image
post.topic.reload
expect(post.topic.image_url).to be_present
end
@ -262,7 +262,7 @@ describe CookedPostProcessor do
it "adds a post image if there's one in the post" do
FastImage.stubs(:size)
expect(reply.image_url).to eq(nil)
cpp.post_process_images
cpp.update_post_image
reply.reload
expect(reply.image_url).to be_present
end

View File

@ -636,7 +636,7 @@ describe Search do
CookedPostProcessor.new(post_uploaded).update_post_image
CookedPostProcessor.new(post_with_image_urls).update_post_image
expect(Search.execute('in:image').posts.map(&:id).sort).to eq([post_uploaded.id, post_with_image_urls.id].sort)
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