diff --git a/wagtail/tests/search/migrations/0003_searchtestchild_page.py b/wagtail/tests/search/migrations/0003_searchtestchild_page.py new file mode 100644 index 0000000000..daf306aa83 --- /dev/null +++ b/wagtail/tests/search/migrations/0003_searchtestchild_page.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0001_squashed_0016_change_page_url_path_to_text_field'), + ('searchtests', '0002_searchtest_tags'), + ] + + operations = [ + migrations.AddField( + model_name='searchtestchild', + name='page', + field=models.ForeignKey(to='wagtailcore.Page', blank=True, null=True), + ), + ] diff --git a/wagtail/tests/search/models.py b/wagtail/tests/search/models.py index 994f35f423..d0142707c6 100644 --- a/wagtail/tests/search/models.py +++ b/wagtail/tests/search/models.py @@ -57,8 +57,14 @@ class SearchTest(models.Model, index.Indexed): class SearchTestChild(SearchTest): subtitle = models.CharField(max_length=255, null=True, blank=True) extra_content = models.TextField() + page = models.ForeignKey('wagtailcore.Page', null=True, blank=True) search_fields = SearchTest.search_fields + [ index.SearchField('subtitle', partial_match=True), index.SearchField('extra_content'), + index.RelatedFields('page', [ + index.SearchField('title', partial_match=True), + index.SearchField('search_description'), + index.FilterField('live'), + ]), ] diff --git a/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py b/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py index 1d397064cb..c7fe29b167 100644 --- a/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py +++ b/wagtail/wagtailsearch/tests/test_elasticsearch_backend.py @@ -749,7 +749,7 @@ class TestElasticSearchMapping(TestCase): 'name': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, 'slug_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, } - } + }, } } } @@ -801,7 +801,7 @@ class TestElasticSearchMappingInheritance(TestCase): self.es_mapping = ElasticSearchMapping(models.SearchTestChild) # Create ES document - self.obj = models.SearchTestChild(title="Hello", subtitle="World") + self.obj = models.SearchTestChild(title="Hello", subtitle="World", page_id=1) self.obj.save() self.obj.tags.add("a tag") @@ -819,6 +819,14 @@ class TestElasticSearchMappingInheritance(TestCase): # New 'extra_content': {'type': 'string', 'include_in_all': True}, 'subtitle': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'page': { + 'type': 'nested', + 'properties': { + 'title': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, + 'search_description': {'type': 'string', 'include_in_all': True}, + 'live_filter': {'index': 'not_analyzed', 'type': 'boolean', 'include_in_all': False}, + } + }, # Inherited 'pk': {'index': 'not_analyzed', 'type': 'string', 'store': 'yes', 'include_in_all': False}, @@ -836,7 +844,7 @@ class TestElasticSearchMappingInheritance(TestCase): 'name': {'type': 'string', 'include_in_all': True, 'index_analyzer': 'edgengram_analyzer'}, 'slug_filter': {'index': 'not_analyzed', 'type': 'string', 'include_in_all': False}, } - } + }, } } } @@ -862,13 +870,18 @@ class TestElasticSearchMappingInheritance(TestCase): # New 'extra_content': '', 'subtitle': 'World', + 'page': { + 'title': 'Root', + 'search_description': '', + 'live_filter': True, + }, # Changed 'content_type': 'searchtests_searchtest_searchtests_searchtestchild', # Inherited 'pk': str(self.obj.pk), - '_partials': ['Hello', 'World', 'a tag'], + '_partials': ['Hello', 'Root', 'World', 'a tag'], 'live_filter': False, 'published_date_filter': None, 'title': 'Hello',