tangled
alpha
login
or
join now
mackuba.eu
/
lycan
35
fork
atom
Don't forget to lycansubscribe
35
fork
atom
overview
issues
1
pulls
pipelines
added support for phrases in quotes
mackuba.eu
6 months ago
6885141b
eb520282
+16
-5
3 changed files
expand all
collapse all
unified
split
app
models
searchable.rb
query_parser.rb
server.rb
+1
-1
app/models/searchable.rb
···
26
26
scope :matching_terms, ->(terms) {
27
27
where(
28
28
(["(posts.text ~* ?)"] * (terms.length)).join(" AND "),
29
29
-
*(terms.map { |x| "\\y#{x}\\y" })
29
29
+
*(terms.map { |x| "\\y" + x.gsub(/\s+/, "\\s+") + "\\y" })
30
30
)
31
31
}
32
32
+14
-3
app/query_parser.rb
···
1
1
class QueryParser
2
2
-
def parse_terms(query)
3
3
-
query = query.strip.gsub('%', "\\%")
4
4
-
query.split(/ +/)
2
2
+
attr_reader :terms
3
3
+
4
4
+
def initialize(query)
5
5
+
@terms = []
6
6
+
query = query.strip
7
7
+
8
8
+
while match = query.match(/".+?"/)
9
9
+
range = match.begin(0)...match.end(0)
10
10
+
phrase = query[range][1..-2].strip
11
11
+
query[range] = ' '
12
12
+
@terms << phrase
13
13
+
end
14
14
+
15
15
+
@terms += query.split(/ +/)
5
16
end
6
17
end
+1
-1
app/server.rb
···
55
55
return json_error('MissingParameter', 'Missing "collection" parameter')
56
56
end
57
57
58
58
-
terms = QueryParser.new.parse_terms(params[:query])
58
58
+
terms = QueryParser.new(params[:query]).terms
59
59
60
60
collection = case params[:collection]
61
61
when 'likes' then user.likes