Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
461e37ca
Commit
461e37ca
authored
Aug 29, 2014
by
Gergely Ujvari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move removeQuoteCharacter into an inner function of _tokenize()
Also fix a snake_case to camelCase conversion
parent
f188e0d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
searchfilters.coffee
h/static/scripts/searchfilters.coffee
+19
-11
No files found.
h/static/scripts/searchfilters.coffee
View file @
461e37ca
...
...
@@ -2,14 +2,6 @@
# It expects a search query string where the search term are separated by space character
# and collects them into the given term arrays
class
SearchFilter
# Small helper function for removing
_removeQuoteCharacter
:
(
text
)
->
start
=
text
.
slice
0
,
1
end
=
text
.
slice
-
1
if
(
start
is
'"'
or
start
is
"'"
)
and
(
start
==
end
)
text
=
text
.
slice
1
,
text
.
length
-
1
text
# This function will slice the search-text input
# Slice character: space,
# but an expression between quotes (' or ") is considered one
...
...
@@ -17,10 +9,26 @@ class SearchFilter
# ["text", "user:john", "to be or not to be"]
_tokenize
:
(
searchtext
)
->
return
[]
unless
searchtext
# Small helper function for removing quote characters
# from the beginning- and end of a string, if the
# quote characters are the same.
# I.e.
# 'foo' -> foo
# "bar" -> bar
# 'foo" -> 'foo"
# bar" -> bar"
_removeQuoteCharacter
=
(
text
)
->
start
=
text
.
slice
0
,
1
end
=
text
.
slice
-
1
if
(
start
is
'"'
or
start
is
"'"
)
and
(
start
==
end
)
text
=
text
.
slice
1
,
text
.
length
-
1
text
tokens
=
searchtext
.
match
/(?:[^\s"']+|"[^"]*"|'[^']*')+/g
# Cut the opening and closing quote characters
tokens
=
tokens
.
map
@
_removeQuoteCharacter
tokens
=
tokens
.
map
_removeQuoteCharacter
# Remove quotes for power search.
# I.e. 'tag:"foo bar"' -> 'tag:foo bar'
...
...
@@ -29,8 +37,8 @@ class SearchFilter
unless
filter
?
then
filter
=
""
if
filter
in
[
'quote'
,
'result'
,
'since'
,
'tag'
,
'text'
,
'uri'
,
'user'
]
token
_p
art
=
token
[
filter
.
length
+
1
..]
tokens
[
index
]
=
filter
+
':'
+
(
@
_removeQuoteCharacter
token_p
art
)
token
P
art
=
token
[
filter
.
length
+
1
..]
tokens
[
index
]
=
filter
+
':'
+
(
_removeQuoteCharacter
tokenP
art
)
tokens
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment