This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from mitodl/feature/skm/669_elasticsearch_dsl
Adds elasticsearch-dsl and adds it alongside Haystack for now.
- Loading branch information
Showing
11 changed files
with
773 additions
and
7 deletions.
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
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
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,30 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
This migration should be able to be copy-pasted exactly for any | ||
future changes to the mapping, with the exception of the dependencies, which | ||
should be updated. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
from search.utils import create_mapping, index_resources | ||
|
||
# pylint: skip-file | ||
|
||
|
||
def create_learning_resource_mapping(apps, schema_editor): | ||
create_mapping() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('learningresources', '0016_revert_backfill'), | ||
('taxonomy', '0007_vocabulary_multi_terms'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_learning_resource_mapping) | ||
] |
Empty file.
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,54 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tests for search engine indexing. | ||
Note that this file started out as a copy | ||
of search/tests/base.py, and was modified to use | ||
the Elasticsearch and Elasticsearch-DSL libraries instead of Haystack. | ||
""" | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
|
||
from learningresources.tests.base import LoreTestCase | ||
from search.utils import search_index | ||
from search.sorting import LoreSortingFields | ||
from taxonomy.models import Term, Vocabulary | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class SearchTestCase(LoreTestCase): | ||
"""Test Elasticsearch indexing.""" | ||
|
||
def setUp(self): | ||
"""Create a vocabulary for our tests.""" | ||
super(SearchTestCase, self).setUp() | ||
self.vocabulary = Vocabulary.objects.create( | ||
repository_id=self.repo.id, name="difficulty", | ||
description="difficulty", required=False, vocabulary_type="f", | ||
weight=1 | ||
) | ||
self.terms = [ | ||
Term.objects.create( | ||
vocabulary_id=self.vocabulary.id, label=label, weight=1 | ||
) | ||
for label in ("easy", "medium", "very difficult", "ancòra", "very") | ||
] | ||
|
||
def search(self, query, sorting=LoreSortingFields.DEFAULT_SORTING_FIELD): | ||
""" | ||
Helper function to perform a search | ||
""" | ||
return search_index(query, repo_slug=self.repo.slug, sort_by=sorting) | ||
|
||
def count_results(self, query=None): | ||
"""Return count of matching indexed records.""" | ||
return self.search(query).count() | ||
|
||
def count_faceted_results(self, vocab, term): | ||
"""Return count of matching indexed records by facet.""" | ||
return search_index( | ||
repo_slug=self.repo.slug, | ||
terms={vocab: term} | ||
).count() |
Oops, something went wrong.