Created
February 20, 2013 20:37
-
-
Save groovecoder/4999372 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from elasticutils.contrib.django.models import DjangoMappingType, Indexable | |
from wiki.models import Document | |
class DocumentType(DjangoMappingType, Indexable): | |
@classmethod | |
def get_model(cls): | |
return Document | |
@classmethod | |
def extract_document(cls, obj_id, obj=None): | |
if obj is None: | |
obj = cls.get_model().objects.get(pk=obj_id) | |
return { | |
'id': obj.id, | |
'title': obj.title, | |
'slug': obj.slug, | |
'locale': obj.locale, | |
'content': obj.rendered_html | |
} | |
@classmethod | |
def get_mapping(cls): | |
return { | |
'id': {'type': 'integer'}, | |
'title': {'type': 'string'}, | |
'slug': {'type': 'string'}, | |
'locale': {'type': 'string', 'index': 'not_analyzed'}, | |
'content': {'type': 'string', 'analyzer': 'snowball'} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment