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
dc769d1b
Commit
dc769d1b
authored
Sep 09, 2013
by
Ujvari Gergely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic visual search facets for streamsearch
parent
54249a9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
143 additions
and
6 deletions
+143
-6
streamsearch.coffee
h/js/streamsearch.coffee
+143
-6
No files found.
h/js/streamsearch.coffee
View file @
dc769d1b
get_quote
=
(
annotation
)
->
if
annotation
.
quote
?
then
return
annotation
.
quote
if
not
'target'
in
annotation
then
return
''
quote
=
'(Reply annotation)'
for
target
in
annotation
[
'target'
]
for
selector
in
target
[
'selector'
]
if
selector
[
'type'
]
is
'TextQuoteSelector'
quote
=
selector
[
'exact'
]
+
' '
quote
class
StreamSearch
this
.
inject
=
[
'$element'
,
'$scope
'
]
this
.
inject
=
[
'$element'
,
'$location'
,
'$scope'
,
'$timeout'
,
'streamfilter
'
]
constructor
:
(
$element
,
$
scope
$element
,
$
location
,
$scope
,
$timeout
,
streamfilter
)
->
$scope
.
path
=
window
.
location
.
protocol
+
'//'
+
window
.
location
.
hostname
+
':'
+
window
.
location
.
port
+
'/__streamer__'
# Generate client ID
buffer
=
new
Array
(
16
)
uuid
.
v4
null
,
buffer
,
0
@
clientID
=
uuid
.
unparse
buffer
# Read search params
search_query
=
''
params
=
$location
.
search
()
if
params
.
query
?
search_query
=
params
.
query
# Initialize Visual search
@
search
=
VS
.
init
container
:
$element
.
find
(
'.visual-search'
)
query
:
search_query
callbacks
:
search
:
(
query
,
searchCollection
)
=>
console
.
log
'search'
# Do not search when no facet is given
unless
searchCollection
.
models
.
length
>
0
return
# Past data limit
limit
=
100
# First cluster the different facets into categories
categories
=
{}
for
searchItem
in
searchCollection
.
models
category
=
searchItem
.
attributes
.
category
value
=
searchItem
.
attributes
.
value
if
category
is
'limit'
then
limit
=
value
else
if
category
is
'text'
# Visualsearch sickly automatically cluster the text field
# (and only the text filed) into a space separated string
catlist
=
[]
for
val
in
value
.
split
' '
catlist
.
push
val
categories
[
category
]
=
catlist
else
if
category
in
categories
then
categories
[
category
].
push
value
else
categories
[
category
]
=
[
value
]
# Assemble the filter json
filter
=
streamfilter
.
setPastDataHits
(
limit
)
.
setMatchPolicyIncludeAll
()
.
noClauses
()
console
.
log
categories
for
category
,
value
of
categories
if
value
.
length
is
1
filter
.
addClausesParse
(
category
+
':i='
+
value
)
else
filter
.
addClausesParse
(
category
+
':i['
+
value
)
$scope
.
initStream
filter
.
getFilter
()
# Update the parameters
$location
.
search
'query'
:
query
facetMatches
:
(
callback
)
=>
return
callback
[
'text'
,
'tag'
,
'quote'
,
'scope'
,
'group'
,
'time'
,
'user
'
],
{
preserveOrder
:
true
}
return
callback
[
'text'
,
'tag'
,
'quote'
,
'time'
,
'user'
,
'limit
'
],
{
preserveOrder
:
true
}
valueMatches
:
(
facet
,
searchTerm
,
callback
)
->
switch
facet
when
'group'
then
callback
[
'Public'
,
'Private'
]
when
'scope'
then
callback
[
'sidebar'
,
'document'
]
when
'limit'
then
callback
[
0
,
10
,
25
,
100
,
250
,
1000
]
when
'time'
callback
[
'5 min'
,
'30 min'
,
'1 hour'
,
'12 hours'
,
'1 day'
,
'1 week'
,
'1 month'
,
'1 year'
],
{
preserveOrder
:
true
}
clearSearch
:
(
original
)
=>
console
.
log
'clearSearch triggered'
# Execute clearSearch's internal method for resetting search
original
()
$location
.
search
{}
$scope
.
initStream
=
(
filter
)
->
if
$scope
.
sock
?
then
$scope
.
sock
.
close
()
$scope
.
annotations
=
new
Array
()
$scope
.
sock
=
new
SockJS
(
$scope
.
path
)
$scope
.
sock
.
onopen
=
=>
sockmsg
=
filter
:
filter
clientID
:
@
clientID
$scope
.
sock
.
send
JSON
.
stringify
sockmsg
$scope
.
sock
.
onclose
=
=>
# stream is closed
$scope
.
sock
.
onmessage
=
(
msg
)
=>
console
.
log
'Got something'
console
.
log
msg
unless
msg
.
data
.
type
?
and
msg
.
data
.
type
is
'annotation-notification'
return
data
=
msg
.
data
.
payload
action
=
msg
.
data
.
options
.
action
unless
data
instanceof
Array
then
data
=
[
data
]
$scope
.
$apply
=>
$scope
.
manage_new_data
data
,
action
$scope
.
manage_new_data
=
(
data
,
action
)
=>
for
annotation
in
data
annotation
.
action
=
action
annotation
.
quote
=
get_quote
annotation
annotation
.
_share_link
=
window
.
location
.
protocol
+
'//'
+
window
.
location
.
hostname
+
':'
+
window
.
location
.
port
+
"/a/"
+
annotation
.
id
annotation
.
_anim
=
'fade'
switch
action
when
'create'
,
'past'
unless
annotation
in
$scope
.
annotations
$scope
.
annotations
.
unshift
annotation
when
'update'
index
=
0
for
ann
in
$scope
.
annotations
if
ann
.
id
is
annotation
.
id
# Remove the original
$scope
.
annotations
.
splice
index
,
1
# Put back the edited
$scope
.
annotations
.
unshift
annotation
break
index
+=
1
when
'delete'
for
ann
in
$scope
.
annotations
if
ann
.
id
is
annotation
.
id
$scope
.
annotations
.
splice
index
,
1
break
index
+=
1
$scope
.
annotations
=
[]
if
search_query
.
length
>
0
$timeout
=>
@
search
.
searchBox
.
app
.
options
.
callbacks
.
search
@
search
.
searchBox
.
value
(),
@
search
.
searchBox
.
app
.
searchQuery
,
500
angular
.
module
(
'h.streamsearch'
,[
'bootstrap'
])
angular
.
module
(
'h.streamsearch'
,[
'
h.streamfilter'
,
'h.filters'
,
'h.directives'
,
'
bootstrap'
])
.
controller
(
'StreamSearchController'
,
StreamSearch
)
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