コード例 #1
0
    def test__init__(self):
        settings.ELASTICSEARCH_DSL_INDEX_SETTINGS = {
            'number_of_replicas': 0,
            'number_of_shards': 2,
        }

        index = Index('test')
        self.assertEqual(index._settings, {
            'number_of_replicas': 0,
            'number_of_shards': 2,
        })

        settings.ELASTICSEARCH_DSL_INDEX_SETTINGS = {}
コード例 #2
0
    def test_documents_add_to_register(self):
        registry = self.registry
        with patch('django_elasticsearch_dsl.indices.registry', new=registry):
            index = Index('test')
            doc_a1 = self._generate_doc_mock(self.ModelA)
            doc_a2 = self._generate_doc_mock(self.ModelA)
            index.document(doc_a1)
            docs = list(registry.get_documents())
            self.assertEqual(len(docs), 1)
            self.assertIs(docs[0], doc_a1)

            index.document(doc_a2)
            docs = registry.get_documents()
            self.assertEqual(docs, set([doc_a1, doc_a2]))
コード例 #3
0
    def test_documents_add_to_register(self):
        registry = DocumentRegistry()
        with patch('django_elasticsearch_dsl.indices.registry', new=registry):
            index = Index('test')
            index.doc_type(self.DocA1)
            docs = list(registry.get_documents())
            self.assertEqual(len(docs), 1)
            self.assertIsInstance(docs[0], self.DocA1)

            index.doc_type(self.DocA2)
            docs = list(registry.get_documents())
            self.assertEqual(len(docs), 2)
            self.assertIsInstance(docs[0], self.DocA1)
            self.assertIsInstance(docs[1], self.DocA2)
コード例 #4
0
from django.conf import settings

from django_elasticsearch_dsl.documents import DocType
from django_elasticsearch_dsl.indices import Index

from django_elasticsearch_dsl.fields import TextField
from django_elasticsearch_dsl.fields import Completion
from django_elasticsearch_dsl.fields import IntegerField
from django_elasticsearch_dsl.fields import ObjectField

from .models import Snippet

snippets = Index('snippets')


@snippets.doc_type
class SnippetDocument(DocType):
    """
    Document for the Snippet model for elasticsearch with fields to index
    """
    desc = TextField(
        attr='desc',
        fields={
            'suggest': Completion(),
        }
    )
    user = ObjectField(
        properties={
            'username': TextField(),
            'id': IntegerField(),
        }
コード例 #5
0
 def test__str__(self):
     index = Index('test')
     self.assertEqual(index.__str__(), 'test')