Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
a2e5f7f3
Commit
a2e5f7f3
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Optionally return event contexts with search results
parent
2f6ad79a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/handlers/search.py
+52
-1
52 additions, 1 deletion
synapse/handlers/search.py
with
52 additions
and
1 deletion
synapse/handlers/search.py
+
52
−
1
View file @
a2e5f7f3
...
@@ -51,6 +51,17 @@ class SearchHandler(BaseHandler):
...
@@ -51,6 +51,17 @@ class SearchHandler(BaseHandler):
"
content.body
"
,
"
content.name
"
,
"
content.topic
"
,
"
content.body
"
,
"
content.name
"
,
"
content.topic
"
,
])
])
filter_dict
=
content
[
"
search_categories
"
][
"
room_events
"
].
get
(
"
filter
"
,
{})
filter_dict
=
content
[
"
search_categories
"
][
"
room_events
"
].
get
(
"
filter
"
,
{})
event_context
=
content
[
"
search_categories
"
][
"
room_events
"
].
get
(
"
event_context
"
,
None
)
if
event_context
is
not
None
:
before_limit
=
int
(
event_context
.
get
(
"
before_limit
"
,
5
))
after_limit
=
int
(
event_context
.
get
(
"
after_limit
"
,
5
))
except
KeyError
:
except
KeyError
:
raise
SynapseError
(
400
,
"
Invalid search query
"
)
raise
SynapseError
(
400
,
"
Invalid search query
"
)
...
@@ -76,14 +87,54 @@ class SearchHandler(BaseHandler):
...
@@ -76,14 +87,54 @@ class SearchHandler(BaseHandler):
user
.
to_string
(),
filtered_events
user
.
to_string
(),
filtered_events
)
)
if
event_context
is
not
None
:
now_token
=
yield
self
.
hs
.
get_event_sources
().
get_current_token
()
contexts
=
{}
for
event
in
allowed_events
:
res
=
yield
self
.
store
.
get_events_around
(
event
.
room_id
,
event
.
event_id
,
before_limit
,
after_limit
)
res
[
"
events_before
"
]
=
yield
self
.
_filter_events_for_client
(
user
.
to_string
(),
res
[
"
events_before
"
]
)
res
[
"
events_after
"
]
=
yield
self
.
_filter_events_for_client
(
user
.
to_string
(),
res
[
"
events_after
"
]
)
res
[
"
start
"
]
=
now_token
.
copy_and_replace
(
"
room_key
"
,
res
[
"
start
"
]
).
to_string
()
res
[
"
end
"
]
=
now_token
.
copy_and_replace
(
"
room_key
"
,
res
[
"
end
"
]
).
to_string
()
contexts
[
event
.
event_id
]
=
res
else
:
contexts
=
{}
# TODO: Add a limit
# TODO: Add a limit
time_now
=
self
.
clock
.
time_msec
()
time_now
=
self
.
clock
.
time_msec
()
for
context
in
contexts
.
values
():
context
[
"
events_before
"
]
=
[
serialize_event
(
e
,
time_now
)
for
e
in
context
[
"
events_before
"
]
]
context
[
"
events_after
"
]
=
[
serialize_event
(
e
,
time_now
)
for
e
in
context
[
"
events_after
"
]
]
results
=
{
results
=
{
e
.
event_id
:
{
e
.
event_id
:
{
"
rank
"
:
rank_map
[
e
.
event_id
],
"
rank
"
:
rank_map
[
e
.
event_id
],
"
result
"
:
serialize_event
(
e
,
time_now
)
"
result
"
:
serialize_event
(
e
,
time_now
),
"
context
"
:
contexts
.
get
(
e
.
event_id
,
{}),
}
}
for
e
in
allowed_events
for
e
in
allowed_events
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment