Skip to content

Instantly share code, notes, and snippets.

@groovecoder
Created February 20, 2013 20:37
Show Gist options
  • Save groovecoder/4999372 to your computer and use it in GitHub Desktop.
Save groovecoder/4999372 to your computer and use it in GitHub Desktop.
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