Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
llonchj committed Nov 1, 2013
2 parents 9a31178 + 50e972b commit 1063af9
Show file tree
Hide file tree
Showing 24 changed files with 603 additions and 640 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ django-tastypie-elasticsearch

ElasticSearch support for django-tastypie

Installation
------------

```
$ pip install django-tastypie-elasticsearch
```

Requirements
------------

Expand All @@ -15,7 +22,6 @@ Requirements
.. _Django: http://djangoproject.com
.. _django-tastypie: http://tastypieapi.org
.. _ElasticSearch: http://elasticsearch.org
.. _pyes: https://github.com/aparo/pyes

How to use?
-----------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('.'))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.test_project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")


# -- General configuration -----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ In your settings.py add ``tastypie`` and ``tastypie_elasticsearch`` to ``INSTALL

You must also add in your settings::

ES_SERVER = 'http://127.0.0.1:9200/'
ES_SERVER = '127.0.0.1:9200'

2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Simple Example
class Meta:

es_server = getattr(settings,
"ES_SERVER", "http://127.0.0.1:9200/")
"ES_SERVER", "127.0.0.1:9200")
es_timeout = 20
indices = ["my_elasticsearch_index"]
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
from setuptools import setup, find_packages

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.test_project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")

def parse_requirements(file_name):
requirements = []
Expand All @@ -23,7 +23,7 @@ def parse_requirements(file_name):

setup(
name = 'django-tastypie-elasticsearch',
version = '0.3.0',
version = '0.4.0',
description = "ElasticSearch Resource for django-tastypie.",
long_description = open(os.path.join(os.path.dirname(__file__), 'README.md')).read(),
author = 'Jordi Llonch',
Expand All @@ -44,5 +44,5 @@ def parse_requirements(file_name):
zip_safe = True,
install_requires=parse_requirements('requirements.txt'),
tests_require=parse_requirements('requirements-test.txt'),
test_suite = 'tests.runtests.runtests',
test_suite='tests.runtests.runtests',
)
9 changes: 2 additions & 7 deletions tastypie_elasticsearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

import logging

logger = logging.getLogger(__name__)

import pkg_resources
VERSION = pkg_resources.get_distribution('django-tastypie-elasticsearch').version

Expand All @@ -14,4 +8,5 @@
__homepage__ = "http://github.com/llonchj/django-tastypie-elasticsearch"
__docformat__ = "restructuredtext"

from .resources import ElasticSearch
from elasticsearch.connection import *
from .resources import ElasticsearchResource
62 changes: 62 additions & 0 deletions tastypie_elasticsearch/paginator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
"""
tastypie.Resource definitions for Elasticsearch
"""

from tastypie.bundle import Bundle
from tastypie.paginator import Paginator
#from tastypie.resources import Resource, DeclarativeMetaclass
#from tastypie.exceptions import NotFound
#from tastypie.utils import trailing_slash
#from tastypie import http


class ElasticsearchResult(list):
def __init__(self, result, query=None):
super(ElasticsearchResult, self).__init__(result["hits"]["hits"])

self.shards = result["_shards"]
self.took = result["took"]
self.timed_out = result["timed_out"]
self.total = result["hits"]["total"]
self.max_score = result["hits"]["max_score"]
self.facets = result.get("facets", [])
self.query = query

class ElasticsearchPaginator(Paginator):

add_search_info = False

def get_count(self):
return self.objects.total

def get_slice(self, limit, offset):
"""
Slices the result set to the specified ``limit`` & ``offset``.
"""
return self.objects

def page(self):
output = super(ElasticsearchPaginator, self).page()

objects = self.objects

if self.add_search_info:
search = dict(
took=objects.took,
max_score=objects.max_score,
shards=objects.shards,
)
if objects.timed_out:
search['timed_out'] = objects.timed_out
if objects.query:
search['query'] = objects.query

output['meta']['search'] = search
else:
output['meta']['took'] = objects.took
if len(objects.facets):
output["facets"] = objects.facets
return output

Loading

0 comments on commit 1063af9

Please sign in to comment.