Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
20227c33
Commit
20227c33
authored
9 years ago
by
Renzo Frigato
Browse files
Options
Downloads
Patches
Plain Diff
add min_score option and docstring comment
parent
4a7754dd
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
api/handlers/searchhandler.py
+9
-4
9 additions, 4 deletions
api/handlers/searchhandler.py
with
9 additions
and
4 deletions
api/handlers/searchhandler.py
+
9
−
4
View file @
20227c33
...
...
@@ -12,7 +12,10 @@ parent_container = {
'
sessions
'
:
'
projects
'
}
def
_filter_body_by_type
(
body
,
doc_type
):
def
_filter_body_by_type
(
body
,
doc_type
,
min_score
):
"""
wrap the body to filter by doc_type
as some full text queries seem to break in ElasticSearch
if, instead, we pass the doc_type in the URL path.
"""
query
=
{
'
query
'
:
{
'
filtered
'
:
{
...
...
@@ -24,7 +27,7 @@ def _filter_body_by_type(body, doc_type):
}
}
},
'
min_score
'
:
0.5
'
min_score
'
:
min_score
}
return
query
...
...
@@ -86,8 +89,9 @@ class SearchHandler(base.RequestHandler):
if
self
.
public_request
:
self
.
abort
(
403
,
'
search is available only for authenticated users
'
)
size
=
self
.
get_param
(
'
size
'
)
min_score
=
self
.
get_param
(
'
min_score
'
,
0.5
)
body
=
self
.
request
.
json_body
query
=
_filter_body_by_type
(
body
,
cont_name
)
query
=
_filter_body_by_type
(
body
,
cont_name
,
min_score
)
try
:
results
=
config
.
es
.
search
(
index
=
'
scitran
'
,
body
=
body
,
_source
=
[
'
_id
'
],
size
=
size
or
10
)
except
elasticsearch
.
exceptions
.
ConnectionError
as
e
:
...
...
@@ -98,8 +102,9 @@ class SearchHandler(base.RequestHandler):
if
self
.
public_request
:
self
.
abort
(
403
,
'
search is available only for authenticated users
'
)
size
=
self
.
get_param
(
'
size
'
)
min_score
=
self
.
get_param
(
'
min_score
'
,
0.5
)
body
=
self
.
request
.
json_body
query
=
_filter_body_by_type
(
body
,
'
files
'
)
query
=
_filter_body_by_type
(
body
,
'
files
'
,
min_score
)
try
:
es_results
=
config
.
es
.
search
(
index
=
'
scitran
'
,
body
=
query
,
size
=
size
or
10
)
## elastic search results are wrapped in subkey ['hits']['hits']
...
...
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