Permalink
Browse files

initial update to pyes 0.17

  • Loading branch information...
1 parent 7f2f24e commit 8fd25bd86b58cfc0d6490cfac08e4846ab4ddf97 Alberto Paro committed Sep 2, 2011
View
22 django_elasticsearch/base.py
@@ -1,14 +1,30 @@
from django.core.exceptions import ImproperlyConfigured
from .creation import DatabaseCreation
-from .operations import DatabaseOperations
from .serializer import Decoder, Encoder
from pyes import ES
from djangotoolbox.db.base import NonrelDatabaseFeatures, \
NonrelDatabaseWrapper, NonrelDatabaseClient, \
NonrelDatabaseValidation, NonrelDatabaseIntrospection
+from djangotoolbox.db.base import NonrelDatabaseOperations
+
+class DatabaseOperations(NonrelDatabaseOperations):
+ compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'
+
+ def sql_flush(self, style, tables, sequence_list):
+ for table in tables:
+ self.connection.db_connection.delete_mapping(self.connection.db_name, table)
+ return []
+
+ def check_aggregate_support(self, aggregate):
+ """
+ This function is meant to raise exception if backend does
+ not support aggregation.
+ """
+ pass
+
class DatabaseFeatures(NonrelDatabaseFeatures):
string_based_auto_field = True
@@ -23,7 +39,7 @@ def table_names(self):
"""
Show defined models
"""
- # TODO: get indexes
+ # TODO: get indices
return []
def sequence_list(self):
@@ -63,7 +79,7 @@ def _ensure_is_connected(self):
decoder=Decoder,
encoder=Encoder,
autorefresh=True,
- default_indexes=[self.db_name])
+ default_indices=[self.db_name])
self._db_connection = self._connection
#auto index creation: check if to remove
View
18 django_elasticsearch/compiler.py
@@ -124,17 +124,15 @@ def __repr__(self):
@safe_call
def fetch(self, low_mark, high_mark):
results = self._get_results()
- #print "results:", results
- hits = results['hits']['hits']
if low_mark > 0:
- hits = hits[low_mark:]
+ results = results[low_mark:]
if high_mark is not None:
- hits = hits[low_mark:high_mark - low_mark]
+ results = results[low_mark:high_mark - low_mark]
- for hit in hits:
- entity = hit["_source"]
- entity['id'] = hit['_id']
+ for hit in results:
+ entity = hit.get_data()
+ entity['id'] = hit.meta.id
yield entity
@safe_call
@@ -176,9 +174,9 @@ def add_filter(self, column, lookup_type, negated, db_type, value):
queryf = self._get_query_type(column, lookup_type, db_type, value)
if negated:
- self.db_query.add(NotFilter(queryf))
+ self.db_query.add([NotFilter(queryf)])
else:
- self.db_query.add(queryf)
+ self.db_query.add([queryf])
def _get_query_type(self, column, lookup_type, db_type, value):
if db_type == "unicode":
@@ -221,7 +219,7 @@ def _get_results(self):
if self._ordering:
query.sort = self._ordering
#print "query", self.query.tables, query
- return self._connection.search(query, indexes=[self.connection.db_name], doc_types=self.query.model._meta.db_table)
+ return self._connection.search(query, indices=[self.connection.db_name], doc_types=self.query.model._meta.db_table)
class SQLCompiler(NonrelCompiler):
"""
View
2 django_elasticsearch/creation.py
@@ -48,7 +48,7 @@ def sql_indexes_for_model(self, model, style):
def sql_create_model(self, model, style, known_models=set()):
from mapping import model_to_mapping
mappings = model_to_mapping(model)
- self.connection.db_connection.put_mapping(model._meta.db_table, mappings)
+ self.connection.db_connection.put_mapping(model._meta.db_table, {mappings.name:mappings.as_dict()})
return [], {}
def set_autocommit(self):
View
12 django_elasticsearch/manager.py
@@ -228,18 +228,6 @@ def values_list(self, *args, **kwargs):
raise Exception("args len must be 1 when flat=True")
return (flat and self.distinct(args[0] if not args[0] in ["id", "pk"] else "_id")) or zip(*[self.distinct(field if not field in ["id", "pk"] else "_id") for field in args])
-#
-# if self._document._meta['geo_indexes'] and \
-# pymongo.version >= "1.5.1":
-# from pymongo import GEO2D
-# for index in self._document._meta['geo_indexes']:
-# self._collection.ensure_index([(index, GEO2D)])
-#
-# # Ensure all needed field indexes are created
-# for field_name, field_instance in self._document._fields.iteritems():
-# if field_instance.__class__.__name__ == 'GeoLocationField':
-# self._collection.ensure_index([(field_name, pymongo.GEO2D),])
-# return self._collection_obj
@property
def _cursor(self):
View
16 django_elasticsearch/operations.py
@@ -1,16 +0,0 @@
-from djangotoolbox.db.base import NonrelDatabaseOperations
-
-class DatabaseOperations(NonrelDatabaseOperations):
- compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'
-
- def sql_flush(self, style, tables, sequence_list):
- for table in tables:
- self.connection.db_connection.delete_mapping(self.connection.db_name, table)
- return []
-
- def check_aggregate_support(self, aggregate):
- """
- This function is meant to raise exception if backend does
- not support aggregation.
- """
- pass
View
3 django_elasticsearch/south.py
@@ -1,6 +1,3 @@
-import inspect
-import re
-
class DatabaseOperations(object):
"""
ES implementation of database operations.
View
9 tests/testproj/manage.py
@@ -2,11 +2,10 @@
import os, sys
from django.core.management import execute_manager
# dirty hack to get the backend working.
-sys.path.insert(0, os.path.abspath('./..'))
-sys.path.insert(0, os.path.abspath('./../..'))
-example_dir = os.path.dirname(__file__)
-sys.path.insert(0, os.path.join(example_dir, '..'))
-
+#sys.path.insert(0, os.path.abspath('./..'))
+#sys.path.insert(0, os.path.abspath('./../..'))
+#example_dir = os.path.dirname(__file__)
+#sys.path.insert(0, os.path.join(example_dir, '..'))
try:
import settings # Assumed to be in the same directory.
except ImportError:
View
6 tests/testproj/settings.py
@@ -24,7 +24,7 @@
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
- 'PORT': '9500',
+ 'PORT': '9200',
'SUPPORTS_TRANSACTIONS': False,
},
}
@@ -100,7 +100,7 @@
'django.contrib.messages',
'testproj.myapp',
'testproj.mixed',
- 'south',
+ #'south',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
)
@@ -109,4 +109,4 @@
ELASTICSEARCH_MANAGED_APPS = ['testproj.myapp', ]
ELASTICSEARCH_MANAGED_MODELS = ['mixed.record', ]
-SOUTH_DATABASE_ADAPTERS = { "default" : "django_elasticsearch.south"}
+#SOUTH_DATABASE_ADAPTERS = { "default" : "django_elasticsearch.south"}

0 comments on commit 8fd25bd

Please sign in to comment.