Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
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
edx
course-discovery
Commits
6dac7a77
Commit
6dac7a77
authored
Aug 14, 2017
by
Clinton Blackburn
Committed by
Clinton Blackburn
Aug 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Overrode search backend's search method"
This reverts commit
a6c66e55
.
parent
a6c66e55
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
51 deletions
+2
-51
course_discovery/apps/edx_haystack_extensions/backends.py
+2
-51
No files found.
course_discovery/apps/edx_haystack_extensions/backends.py
View file @
6dac7a77
import
logging
import
elasticsearch
from
haystack.backends
import
log_query
from
haystack.backends.elasticsearch_backend
import
ElasticsearchSearchBackend
,
ElasticsearchSearchEngine
from
haystack.models
import
SearchResult
from
course_discovery.apps.edx_haystack_extensions.elasticsearch_boost_config
import
get_elasticsearch_boost_config
logger
=
logging
.
getLogger
(
__name__
)
class
SimpleQuerySearchBackendMixin
(
object
):
"""
...
...
@@ -128,54 +121,12 @@ class ConfigurableElasticBackend(ElasticsearchSearchBackend):
# pylint: disable=abstract-method
class
EdxElasticsearchSearchBackend
(
SimpleQuerySearchBackendMixin
,
NonClearingSearchBackendMixin
,
ConfigurableElasticBackend
):
@log_query
def
search
(
self
,
query_string
,
**
kwargs
):
if
len
(
query_string
)
==
0
:
return
{
'results'
:
[],
'hits'
:
0
,
}
# NOTE (CCB): Haystack by default attempts to read/update the index mapping. Given that our mapping doesn't
# frequently change, this is a waste of three API calls. Stop it! We set our mapping when we create the index.
self
.
setup_complete
=
True
# if not self.setup_complete:
# self.setup()
logger
.
info
(
'DEBUG: Skipped Haystack setup call'
)
search_kwargs
=
self
.
build_search_kwargs
(
query_string
,
**
kwargs
)
search_kwargs
[
'from'
]
=
kwargs
.
get
(
'start_offset'
,
0
)
order_fields
=
set
()
for
order
in
search_kwargs
.
get
(
'sort'
,
[]):
for
key
in
order
.
keys
():
order_fields
.
add
(
key
)
geo_sort
=
'_geo_distance'
in
order_fields
end_offset
=
kwargs
.
get
(
'end_offset'
)
start_offset
=
kwargs
.
get
(
'start_offset'
,
0
)
if
end_offset
is
not
None
and
end_offset
>
start_offset
:
search_kwargs
[
'size'
]
=
end_offset
-
start_offset
try
:
# pylint: disable=unexpected-keyword-arg
raw_results
=
self
.
conn
.
search
(
body
=
search_kwargs
,
index
=
self
.
index_name
,
doc_type
=
'modelresult'
,
_source
=
True
)
except
elasticsearch
.
TransportError
as
e
:
if
not
self
.
silently_fail
:
raise
self
.
log
.
error
(
"Failed to query Elasticsearch using '
%
s':
%
s"
,
query_string
,
e
,
exc_info
=
True
)
raw_results
=
{}
return
self
.
_process_results
(
raw_results
,
highlight
=
kwargs
.
get
(
'highlight'
),
result_class
=
kwargs
.
get
(
'result_class'
,
SearchResult
),
distance_point
=
kwargs
.
get
(
'distance_point'
),
geo_sort
=
geo_sort
)
return
super
()
.
search
(
query_string
,
**
kwargs
)
class
EdxElasticsearchSearchEngine
(
ElasticsearchSearchEngine
):
...
...
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