Commit Graph

11629 Commits

Author SHA1 Message Date
evazion
98a9b2484b post queries: parse order:*_count synonyms. 2022-04-06 23:57:55 -05:00
evazion
86de5cb5d2 posts: fixup flagger: metatag.
Fix regression in 01a22930e.
2022-04-06 23:57:50 -05:00
evazion
01a22930e7 posts: move attribute search methods from PostQueryBuilder to Post.
Move `status_matches` etc methods from PostQueryBuilder to Post. This is
to make refactoring to use the new query parser easier.
2022-04-06 20:25:09 -05:00
evazion
c707190bc1 posts: refactor modules to use concerning. 2022-04-06 20:25:00 -05:00
evazion
a4d43ae72a post queries: track whether metatag values are quoted.
This is necessary for the `commentary:` metatag, which has different
behavior depending on whether the metatag value is quoted. For example,
`commentary:translated` finds translated commentaries, while
`commentary:"translated"` finds commentaries containing the literal word
"translated".
2022-04-06 17:20:27 -05:00
evazion
2adc530ba0 post queries: parse count metatag synonyms. 2022-04-06 17:20:27 -05:00
evazion
f15f365375 Merge pull request #4952 from thayol/fix-negated-ord
Search: "Fix" negated ordered metatags
2022-04-06 04:43:24 -05:00
evazion
783419bcd7 post queries: support single-quoted strings in metatags. 2022-04-06 00:18:38 -05:00
evazion
88be28ae36 users: optimize commented/noted post count on user profiles.
Count the number of commented and noted posts directly, instead of
indirectly by counting the number of posts in a `commenter:<name>` or
`noteupdater:<name>` search. This is faster because it generates
better SQL.
2022-04-06 00:18:29 -05:00
evazion
71c8768fe2 autocomplete: fix autocomplete not working.
Broken by 7fe7175. PostQuery is no longer normalized by default, so the
AST structure not the same as before, which broke autocomplete.
2022-04-04 18:09:56 -05:00
evazion
7fe717506d post queries: add methods for normalizing queries. 2022-04-04 03:56:56 -05:00
evazion
1957cb354e post queries: add #replace_aliases method. 2022-04-04 03:56:54 -05:00
evazion
bf7c721815 post queries: refactor AST #simplify method.
Refactor the `PostQuery::AST#simplify` method to split it into three
methods: `#trim` to eliminate redundant AND and OR clauses, `#simplify`
to expand deeply nested subexpressions, and `#sort` to sort the query
into alphabetical order.

This is so we can normalize queries written by users by parsing and
rewriting them, but without expanding out nested subexpressions, which
can substantially alter the way the query is written.
2022-04-04 00:48:40 -05:00
evazion
8055c4f172 Fix stale site icons.
Fix artist URLs still showing old cached site icons because the URL
didn't change when the file was updated. Use `image_pack_tag` so that
the filename includes the hash, so that the URL changes when the file
changes.
2022-04-03 22:41:50 -05:00
evazion
70c5332be8 artist urls: add index on url column. 2022-04-03 17:08:36 -05:00
NamelessContributor
8ea514ad1c css: add auto theme preference. fixes #5084
This is the new default. Users who previously used the light theme will
be migrated to the auto setting.
2022-04-03 18:05:34 +02:00
NamelessContributor
db5918a783 css: rename base/040_colors.css -> scss 2022-04-03 17:39:30 +02:00
evazion
83f5124a5e Fix #5091: Normalize reddit sources. 2022-04-03 03:46:17 -05:00
evazion
d96db350f3 pixiv: fix non-www Pixiv urls not being recognized.
Fix non-www Pixiv URLs (e.g. `https://pixiv.net/users/3584828`) URLs not
being recognized by the URL parser.
2022-04-03 03:07:42 -05:00
evazion
8ef72d59c1 artists: allow url_matches param to take multiple urls.
Pass as an array or space-separated string:

* https://danbooru.donmai.us/artists?search[url_matches]=https://www.pixiv.net/en/users/32777+https://www.pixiv.net/en/users/3584828
* https://danbooru.donmai.us/artists?search[url_matches][]=https://www.pixiv.net/en/users/32777&search[url_matches][]=https://www.pixiv.net/en/users/3584828
2022-04-03 02:54:30 -05:00
evazion
0d480eb832 artist urls: stop using normalized_url.
Stop the last remaining uses of the `artist_urls.normalized_url` column.
It's already no longer used by the artist finder. The only remaining
uses were by API users. Those users should use the `url` column instead.
2022-04-02 23:58:01 -05:00
evazion
86e9cf1d05 artist urls: make normalized_url nullable.
Make the normalized_url column nullable in preparation for dropping it.
2022-04-02 23:30:39 -05:00
evazion
ca8083465b newgrounds: exclude links to other works in commentary.
Sometimes when a Newgrounds post is part of a set, there is a list of
links to other posts in the set in the artist's commentary. Exclude
these links because they're not really part of the commentary.

Example: https://www.newgrounds.com/art/view/boxofwant/annie-hughes-1 (NSFW)
2022-04-02 23:13:26 -05:00
evazion
6ad7df0ded news updates: fix updates not being visible. 2022-04-02 18:19:50 -05:00
evazion
10e3416c95 related tags: better tag name selector.
Cherry-picked April Fool's day fix.
2022-04-02 18:19:46 -05:00
evazion
6807ed7786 Fix #5077: Images rated "Adult" on Newgrounds no longer upload. 2022-04-02 17:55:29 -05:00
evazion
2543a2b05b posts: remove tag limit from searches. 2022-04-01 22:06:42 -05:00
Thayol
e45e42d479 Use longer lines instead of conditional variables (CodeClimate) 2022-03-31 23:38:40 +02:00
Thayol
70c81f7d49 Change local variable instead of passed object 2022-03-31 23:35:22 +02:00
evazion
f2cdc5fd73 Update Ruby gems and Yarn packages. 2022-03-31 03:26:47 -05:00
evazion
9c5b60b630 sources: normalize artist urls for ask.fm, ameblo.jp, anidb.net, animenewsnetwork.com 2022-03-31 02:36:17 -05:00
evazion
54cfbf84c6 pawoo: fix www.pawoo.net urls not being normalized to pawoo.net.
Fix artist URLs like https://www.pawoo.net/@01051708 not being normalized to https://pawoo.net/@01051708.
2022-03-31 02:17:51 -05:00
evazion
990d7f6380 instagram: strip '@' from usernames in profile urls. 2022-03-31 02:02:28 -05:00
evazion
f31878bc2c Fix blank error page when performing search with invalid regex.
Fix searches like this:

    https://danbooru.donmai.us/artist_urls?search[url_not_regex]=https://www/.artstation/.com/[a-zA-Z0-9-.]

returning a HTTP 500 error with a blank page.

Here the problem is that Postgres raises an error because `[a-zA-Z0-9-.]`
is an invalid character class (it should be `[a-ZA-Z0-9.-]`). This error
happens on the error page itself, when rendering the <link rel="next"> /
<link rel="prev"> links in the <head>, so it causes the error page to fail.
2022-03-30 22:45:44 -05:00
evazion
b8f154d301 artists: add more artist url icons. 2022-03-30 22:04:24 -05:00
evazion
bfbc932025 Fix #5082: NoMethodError when searching an old-style dead fanbox url in artist urls.
This API call:

    # profile: https://www.pixiv.net/fanbox/creator/40684196
    curl -H "Origin: https://fanbox.cc" "https://api.fanbox.cc/creator.get?userId=40684196"

returns `{ "body": nil }` when the artist is deleted. We didn't expect `body` to be nil.

Also fix it so that `profile_url` returns the `https://www.pixiv.net/fanbox/creator/40684196`
URL if we can't get the `https://<username>.fanbox.cc` URL, usually because the API call failed
because the artist is deleted.
2022-03-30 18:19:08 -05:00
Thayol
89b40a65ba Refactor to hash from multiple ifs 2022-03-30 17:54:52 +02:00
evazion
a272c19b98 Fix #5078: Pixiv booth upload broken.
Allow image URLs from https://booth.pximg.net to be uploaded. Fix bug
where Booth.pm URLs were incorrectly caught by the Pixiv extractor.
2022-03-30 03:25:42 -05:00
evazion
04551b8154 autocomplete: replace calls to PostQueryBuilder with PostQuery. 2022-03-30 02:12:25 -05:00
evazion
6edff247f2 search: replace calls to PostQueryBuilder#fast_count with PostQuery#fast_count.
Prepare a few more places for the new tag search parser.
2022-03-30 01:37:11 -05:00
evazion
8c9e045a9c PostQuery::AST: fix #to_infix to not add unnecessary parentheses.
* Fix the `#to_infix` method to not add unnecessary parentheses around subexpressions.
* Fix metatags to add quotes around values when necessary.
2022-03-30 01:05:08 -05:00
evazion
fb0a7851bf BURs: fix mass update A -> B not being allowed.
Fix mass updates of the form `mass update A -> B` not being allowed.

This was originally because after `rename` was introduced, we wanted to
prevent people from using mass updates to move tags. Now, `mass update A -> B`
adds B to all posts tagged A instead of moving A to B. So `mass update A -> B`
should no longer be disallowed.

This also makes it so that it's an error to create a mass update with a
syntax error in the search. Before searches couldn't have syntax errors,
but now with the new query parser it's possible.
2022-03-29 21:31:28 -05:00
evazion
226faae8ec BURs: fix tags field not finding all BURs with that tag.
Fix the Tags field in the BUR search form not finding all BURs
mentioning that tag. Specifically, tags that were part of a mass update,
and that were prefixed with `~` or `-` (OR tags and NOT tags), weren't
indexed as tags affected by the BUR.

This requires re-running script/fixes/064_initialize_bulk_update_request_tags.rb
to fix old BURs.
2022-03-29 21:06:24 -05:00
evazion
823fa5c6e9 search: switch to new tag search parser in a few places. 2022-03-29 18:21:47 -05:00
evazion
4c7cfc73c6 search: add new tag search parser.
Add a new tag tag search parser that supports full boolean expressions, including `and`,
`or`, and `not` operators and parenthesized subexpressions.

This is only the parser itself, not the code for converting the search into SQL. The new
parser isn't used yet for actual searches. Searches still use the old parser.

Some example syntax:

* `1girl 1boy`
* `1girl and 1boy` (same as `1girl 1boy`)
* `1girl or 1boy`
* `~1girl ~1boy` (same as `1girl or 1boy`)
* `1girl and ((blonde_hair blue_eyes) or (red_hair green_eyes))`
* `1girl ~(blonde_hair blue_eyes) ~(red_hair green_eyes)` (same as above)
* `1girl -(blonde_hair blue_eyes)`
* `*_hair *_eyes`
* `*_hair or *_eyes`
* `user:evazion or fav:evazion`
* `~user:evazion ~fav:evazion`

Rules:

AND is implicit between terms, but may be written explicitly:

* `a b c` is `a and b and c`

AND has higher precedence (binds tighter) than OR:

* `a or b and c or d` is `a or (b and c) or d`
* `a or b c or d e` is `a or (b and c) or (d and e)`

All `~` operators in the same subexpression are combined into a single OR:

* `a b ~c ~d` is `a b (c or d)`
* `~a ~b and ~c ~d` is `(a or b) (c or d)`
* `(~a ~b) (~c ~d)` is `(a or b) (c or d)`

A single `~` operator in a subexpression by itself is ignored:

* `a ~b` is `a b`
* `~a and ~b` is `a and b`, which is `a b`
* `(~a) ~b` is `a ~b`, which is `a b`

The parser is written as a backtracking recursive descent parser built on top of
StringScanner and a handful of parser combinators. The parser generates an AST, which is
then simplified using Boolean algebra to remove redundant nodes and to convert the
expression to conjunctive normal form (that is, a product of sums, or an AND of ORs).
2022-03-29 18:21:46 -05:00
evazion
8b2798d487 Merge pull request #5068 from NamelessContributor/patch-1
tag_list_component: fix overflow of some long tags
2022-03-27 02:29:37 -05:00
evazion
a12f82cb86 tests: fix tag name '(' test broken by dd21d4b45. 2022-03-26 16:31:20 -05:00
evazion
231075fb49 artists: fix artist finder to return nothing if it finds too many duplicates 2022-03-26 15:08:55 -05:00
evazion
44903abe28 BURs: change mass updates to not remove left-hand side tags.
Change mass updates to not automatically remove the left-hand side tags
from the post. This won't work with full boolean searches in the future
and already doesn't work with complex searches involving metatags or OR-tags.
2022-03-26 02:01:04 -05:00
evazion
dd21d4b45c tags: don't allow tags to start with '(' or '['.
Also don't allow the words 'and', 'or', and 'not'.

Related to #4949.
2022-03-26 00:38:34 -05:00