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
acb7fdc9
Commit
acb7fdc9
authored
Oct 03, 2016
by
Matthew Piatetsky
Committed by
GitHub
Oct 03, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #340 from edx/bderusha/title-boost
Add title boosting for search queries
parents
23a9a7f1
bf9a5190
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
course_discovery/apps/api/v1/views.py
+6
-0
course_discovery/apps/course_metadata/search_indexes.py
+11
-2
No files found.
course_discovery/apps/api/v1/views.py
View file @
acb7fdc9
...
...
@@ -14,6 +14,8 @@ from drf_haystack.mixins import FacetMixin
from
drf_haystack.viewsets
import
HaystackViewSet
from
dry_rest_permissions.generics
import
DRYPermissions
from
edx_rest_framework_extensions.permissions
import
IsSuperuser
from
haystack.inputs
import
AutoQuery
from
haystack.query
import
SQ
from
rest_framework
import
status
,
viewsets
from
rest_framework.decorators
import
detail_route
,
list_route
from
rest_framework.exceptions
import
PermissionDenied
,
ParseError
...
...
@@ -602,6 +604,10 @@ class BaseHaystackViewSet(FacetMixin, HaystackViewSet):
def
filter_facet_queryset
(
self
,
queryset
):
queryset
=
super
()
.
filter_facet_queryset
(
queryset
)
q
=
self
.
request
.
query_params
.
get
(
'q'
)
if
q
:
queryset
=
queryset
.
filter
(
SQ
(
text
=
AutoQuery
(
q
))
|
SQ
(
title
=
AutoQuery
(
q
)))
facet_serializer_cls
=
self
.
get_facet_serializer_class
()
field_queries
=
getattr
(
facet_serializer_cls
.
Meta
,
'field_queries'
,
{})
...
...
course_discovery/apps/course_metadata/search_indexes.py
View file @
acb7fdc9
...
...
@@ -6,6 +6,15 @@ from opaque_keys.edx.keys import CourseKey
from
course_discovery.apps.course_metadata.choices
import
CourseRunStatus
,
ProgramStatus
from
course_discovery.apps.course_metadata.models
import
Course
,
CourseRun
,
Program
# http://django-haystack.readthedocs.io/en/v2.5.0/boost.html#field-boost
# Boost title over all other parameters (multiplicative)
# The max boost received from our boosting functions is ~6.
# Having a boost of 25 for title gives most relevant titles a score higher
# than our other boosting (which is what we want). But it's all relative.
# If we altered our boosting functions to have a max score of 10
# we would probably want to bump this number.
TITLE_FIELD_BOOST
=
25.0
class
OrganizationsMixin
:
def
format_organization
(
self
,
organization
):
...
...
@@ -49,7 +58,7 @@ class BaseIndex(indexes.SearchIndex):
class
BaseCourseIndex
(
OrganizationsMixin
,
BaseIndex
):
key
=
indexes
.
CharField
(
model_attr
=
'key'
,
stored
=
True
)
title
=
indexes
.
CharField
(
model_attr
=
'title'
)
title
=
indexes
.
CharField
(
model_attr
=
'title'
,
boost
=
TITLE_FIELD_BOOST
)
short_description
=
indexes
.
CharField
(
model_attr
=
'short_description'
,
null
=
True
)
full_description
=
indexes
.
CharField
(
model_attr
=
'full_description'
,
null
=
True
)
subjects
=
indexes
.
MultiValueField
(
faceted
=
True
)
...
...
@@ -170,7 +179,7 @@ class ProgramIndex(BaseIndex, indexes.Indexable, OrganizationsMixin):
model
=
Program
uuid
=
indexes
.
CharField
(
model_attr
=
'uuid'
)
title
=
indexes
.
CharField
(
model_attr
=
'title'
)
title
=
indexes
.
CharField
(
model_attr
=
'title'
,
boost
=
TITLE_FIELD_BOOST
)
subtitle
=
indexes
.
CharField
(
model_attr
=
'subtitle'
)
type
=
indexes
.
CharField
(
model_attr
=
'type__name'
,
faceted
=
True
)
marketing_url
=
indexes
.
CharField
(
null
=
True
)
...
...
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