forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set course display name in Arabic at course search page, added edx-se…
…rach module into platform. (Fixes openedx#3)
- Loading branch information
1 parent
82d0d89
commit c8ad295
Showing
22 changed files
with
4,277 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
""" courseware search app for indexing / searching courseware content """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" search business logic implementations """ | ||
from datetime import datetime | ||
|
||
from django.conf import settings | ||
|
||
from .filter_generator import SearchFilterGenerator | ||
from .search_engine_base import SearchEngine | ||
from .result_processor import SearchResultProcessor | ||
from .utils import DateRange | ||
|
||
# Default filters that we support, override using COURSE_DISCOVERY_FILTERS setting if desired | ||
DEFAULT_FILTER_FIELDS = ["org", "modes", "language"] | ||
|
||
|
||
def course_discovery_filter_fields(): | ||
""" look up the desired list of course discovery filter fields """ | ||
return getattr(settings, "COURSE_DISCOVERY_FILTERS", DEFAULT_FILTER_FIELDS) | ||
|
||
|
||
def course_discovery_facets(): | ||
""" Discovery facets to include, by default we specify each filter field with unspecified size attribute """ | ||
return getattr(settings, "COURSE_DISCOVERY_FACETS", {field: {} for field in course_discovery_filter_fields()}) | ||
|
||
|
||
class NoSearchEngineError(Exception): | ||
""" NoSearchEngineError exception to be thrown if no search engine is specified """ | ||
pass | ||
|
||
|
||
def perform_search( | ||
search_term, | ||
user=None, | ||
size=10, | ||
from_=0, | ||
course_id=None): | ||
""" Call the search engine with the appropriate parameters """ | ||
# field_, filter_ and exclude_dictionary(s) can be overridden by calling application | ||
# field_dictionary includes course if course_id provided | ||
(field_dictionary, filter_dictionary, exclude_dictionary) = SearchFilterGenerator.generate_field_filters( | ||
user=user, | ||
course_id=course_id | ||
) | ||
|
||
searcher = SearchEngine.get_search_engine(getattr(settings, "COURSEWARE_INDEX_NAME", "courseware_index")) | ||
if not searcher: | ||
raise NoSearchEngineError("No search engine specified in settings.SEARCH_ENGINE") | ||
|
||
results = searcher.search_string( | ||
search_term, | ||
field_dictionary=field_dictionary, | ||
filter_dictionary=filter_dictionary, | ||
exclude_dictionary=exclude_dictionary, | ||
size=size, | ||
from_=from_, | ||
doc_type="courseware_content", | ||
) | ||
|
||
# post-process the result | ||
for result in results["results"]: | ||
result["data"] = SearchResultProcessor.process_result(result["data"], search_term, user) | ||
|
||
results["access_denied_count"] = len([r for r in results["results"] if r["data"] is None]) | ||
results["results"] = [r for r in results["results"] if r["data"] is not None] | ||
|
||
return results | ||
|
||
|
||
def course_discovery_search(search_term=None, size=20, from_=0, field_dictionary=None): | ||
""" | ||
Course Discovery activities against the search engine index of course details | ||
""" | ||
# We'll ignore the course-enrollemnt informaiton in field and filter | ||
# dictionary, and use our own logic upon enrollment dates for these | ||
use_search_fields = ["org"] | ||
(search_fields, _, exclude_dictionary) = SearchFilterGenerator.generate_field_filters() | ||
use_field_dictionary = {} | ||
use_field_dictionary.update({field: search_fields[field] for field in search_fields if field in use_search_fields}) | ||
if field_dictionary: | ||
use_field_dictionary.update(field_dictionary) | ||
if not getattr(settings, "SEARCH_SKIP_ENROLLMENT_START_DATE_FILTERING", False): | ||
use_field_dictionary["enrollment_start"] = DateRange(None, datetime.utcnow()) | ||
|
||
searcher = SearchEngine.get_search_engine(getattr(settings, "COURSEWARE_INDEX_NAME", "courseware_index")) | ||
if not searcher: | ||
raise NoSearchEngineError("No search engine specified in settings.SEARCH_ENGINE") | ||
|
||
results = searcher.search( | ||
query_string=search_term, | ||
doc_type="course_info", | ||
size=size, | ||
from_=from_, | ||
# only show when enrollment start IS provided and is before now | ||
field_dictionary=use_field_dictionary, | ||
# show if no enrollment end is provided and has not yet been reached | ||
filter_dictionary={"enrollment_end": DateRange(datetime.utcnow(), None)}, | ||
exclude_dictionary=exclude_dictionary, | ||
facet_terms=course_discovery_facets(), | ||
) | ||
|
||
return results |
Oops, something went wrong.