Commit 57827351 authored by Ujvari Gergely's avatar Ujvari Gergely Committed by gergely-ujvari

Searchfilter handles empty query

parent ed4a2b9e
......@@ -19,9 +19,6 @@ class SearchFilter
tokens
generateFacetedFilter: (searchtext) ->
return unless searchtext
terms = @_tokenize(searchtext)
any = []
quote = []
result = []
......@@ -31,51 +28,54 @@ class SearchFilter
uri = []
user = []
for term in terms
filter = term.slice 0, term.indexOf ":"
unless filter? then filter = ""
switch filter
when 'quote' then quote.push term[6..]
when 'result' then result.push term[7..]
when 'since'
# We'll turn this into seconds
time = term[6..].toLowerCase()
if time.match /^\d+$/
# Only digits, assuming seconds
since.push time
if time.match /^\d+sec$/
# Time given in seconds
t = /^(\d+)sec$/.exec(time)[1]
since.push t
if time.match /^\d+min$/
# Time given in minutes
t = /^(\d+)min$/.exec(time)[1]
since.push t * 60
if time.match /^\d+hour$/
# Time given in hours
t = /^(\d+)hour$/.exec(time)[1]
since.push t * 60 * 60
if time.match /^\d+day$/
# Time given in days
t = /^(\d+)day$/.exec(time)[1]
since.push t * 60 * 60 * 24
if time.match /^\d+week$/
# Time given in week
t = /^(\d+)week$/.exec(time)[1]
since.push t * 60 * 60 * 24 * 7
if time.match /^\d+month$/
# Time given in month
t = /^(\d+)month$/.exec(time)[1]
since.push t * 60 * 60 * 24 * 30
if time.match /^\d+year$/
# Time given in year
t = /^(\d+)year$/.exec(time)[1]
since.push t * 60 * 60 * 24 * 365
when 'tag' then tag.push term[4..]
when 'text' then text.push term[5..]
when 'uri' then uri.push term[4..]
when 'user' then user.push term[5..]
else any.push term
if searchtext
terms = @_tokenize(searchtext)
for term in terms
filter = term.slice 0, term.indexOf ":"
unless filter? then filter = ""
switch filter
when 'quote' then quote.push term[6..]
when 'result' then result.push term[7..]
when 'since'
# We'll turn this into seconds
time = term[6..].toLowerCase()
if time.match /^\d+$/
# Only digits, assuming seconds
since.push time
if time.match /^\d+sec$/
# Time given in seconds
t = /^(\d+)sec$/.exec(time)[1]
since.push t
if time.match /^\d+min$/
# Time given in minutes
t = /^(\d+)min$/.exec(time)[1]
since.push t * 60
if time.match /^\d+hour$/
# Time given in hours
t = /^(\d+)hour$/.exec(time)[1]
since.push t * 60 * 60
if time.match /^\d+day$/
# Time given in days
t = /^(\d+)day$/.exec(time)[1]
since.push t * 60 * 60 * 24
if time.match /^\d+week$/
# Time given in week
t = /^(\d+)week$/.exec(time)[1]
since.push t * 60 * 60 * 24 * 7
if time.match /^\d+month$/
# Time given in month
t = /^(\d+)month$/.exec(time)[1]
since.push t * 60 * 60 * 24 * 30
if time.match /^\d+year$/
# Time given in year
t = /^(\d+)year$/.exec(time)[1]
since.push t * 60 * 60 * 24 * 365
when 'tag' then tag.push term[4..]
when 'text' then text.push term[5..]
when 'uri' then uri.push term[4..]
when 'user' then user.push term[5..]
else any.push term
any:
terms: any
operator: 'and'
......
......@@ -783,7 +783,6 @@ class ViewFilter
#
# Returns the list of matching annotation IDs.
filter: (annotations, query) =>
return [] unless query.query
filters = @searchfilter.generateFacetedFilter query.query
results = []
......
......@@ -5,7 +5,7 @@
color: $gray;
&.simple-search-inactive {
color: $grayLighter;
color: $gray-lighter;
}
}
......@@ -26,8 +26,8 @@
padding-left: 2em;
.simple-search-inactive & {
background-color: $grayLightest;
border-color: $grayLightest !important;
background-color: $gray-lightest;
border-color: $gray-lightest !important;
}
}
......@@ -45,7 +45,7 @@
top: 50%;
border: none;
border-radius: 50%;
background: $grayLight;
background: $gray-light;
color: #fff;
width: 16px;
height: 16px;
......@@ -58,7 +58,7 @@
&:focus, &:hover, &:active:not([disabled]) {
@include transition(background-color 200ms ease-in);
background-color: $grayLight;
background-color: $gray-light;
color: #fff;
border: none;
background-image: none;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment