autocomplete: fix metatags not completing until a character is typed.

Fix metatags not showing autocomplete results until after the first
letter was typed. For example, typing `filetype:` didn't show any
completions until another letter was typed. Now typing `filetype:` shows
all available file types.

This was because `filetype:` by itself wasn't recognized as a valid
search before, since metatags always required a value. Now it is a valid
search, so it's technically possible to search for `filetype:` by
itself. In this case the metatag value will be the empty string, which
will return no results because there are no posts where the filetype is
the empty string.

This sounds nonsensical, but it's potentially useful for metatags like
the `source:` metatag, where searching for posts with an empty source
does make sense. It was also technically possible before by searching
for `source:""`, so making the value optional doesn't change anything.
This commit is contained in:
evazion
2022-04-29 22:05:25 -05:00
parent 031ab1e833
commit 906ac25221
3 changed files with 3 additions and 1 deletions

View File

@@ -172,7 +172,7 @@ class PostQuery
expect("'")
[true, a]
else
[false, string(/[^ ]+/)]
[false, string(/[^ ]*/)]
end
end

View File

@@ -896,6 +896,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
assert_tag_match([post3], "source:NONE")
assert_tag_match([post3], 'source:""')
assert_tag_match([post3], "source:''")
assert_tag_match([post3], "source:")
assert_tag_match([post2, post1], "-source:none")
assert_tag_match([post2, post1], "-source:''")
assert_tag_match([post2, post1], '-source:""')

View File

@@ -114,6 +114,7 @@ class PostQueryParserTest < ActiveSupport::TestCase
assert_parse_equals('source:"foo bar"', 'source:"foo bar"')
assert_parse_equals('source:foobar"(', 'source:foobar"(')
assert_parse_equals('source:', 'source:')
assert_parse_equals('source:""', 'source:""')
assert_parse_equals('source:"\""', 'source:"\""')
assert_parse_equals(%q{source:"don't say \"lazy\" okay"}, %q{source:"don't say \"lazy\" okay"})