Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial update to pyes 0.17

commit 8fd25bd86b58cfc0d6490cfac08e4846ab4ddf97 1 parent 7f2f24e
authored September 02, 2011
22  django_elasticsearch/base.py
... ...
@@ -1,7 +1,6 @@
1 1
 from django.core.exceptions import ImproperlyConfigured
2 2
 
3 3
 from .creation import DatabaseCreation
4  
-from .operations import DatabaseOperations
5 4
 from .serializer import Decoder, Encoder
6 5
 from pyes import ES
7 6
 
@@ -9,6 +8,23 @@
9 8
     NonrelDatabaseWrapper, NonrelDatabaseClient, \
10 9
     NonrelDatabaseValidation, NonrelDatabaseIntrospection
11 10
 
  11
+from djangotoolbox.db.base import NonrelDatabaseOperations
  12
+
  13
+class DatabaseOperations(NonrelDatabaseOperations):
  14
+    compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'
  15
+
  16
+    def sql_flush(self, style, tables, sequence_list):
  17
+        for table in tables:
  18
+            self.connection.db_connection.delete_mapping(self.connection.db_name, table)
  19
+        return []
  20
+
  21
+    def check_aggregate_support(self, aggregate):
  22
+        """
  23
+        This function is meant to raise exception if backend does
  24
+        not support aggregation.
  25
+        """
  26
+        pass
  27
+    
12 28
 class DatabaseFeatures(NonrelDatabaseFeatures):
13 29
     string_based_auto_field = True
14 30
 
@@ -23,7 +39,7 @@ def table_names(self):
23 39
         """
24 40
         Show defined models
25 41
         """
26  
-        # TODO: get indexes
  42
+        # TODO: get indices
27 43
         return []
28 44
 
29 45
     def sequence_list(self):
@@ -63,7 +79,7 @@ def _ensure_is_connected(self):
63 79
                                   decoder=Decoder,
64 80
                                   encoder=Encoder,
65 81
                                   autorefresh=True,
66  
-                                  default_indexes=[self.db_name])
  82
+                                  default_indices=[self.db_name])
67 83
 
68 84
             self._db_connection = self._connection
69 85
             #auto index creation: check if to remove
18  django_elasticsearch/compiler.py
@@ -124,17 +124,15 @@ def __repr__(self):
124 124
     @safe_call
125 125
     def fetch(self, low_mark, high_mark):
126 126
         results = self._get_results()
127  
-        #print "results:", results
128  
-        hits = results['hits']['hits']
129 127
 
130 128
         if low_mark > 0:
131  
-            hits = hits[low_mark:]
  129
+            results = results[low_mark:]
132 130
         if high_mark is not None:
133  
-            hits = hits[low_mark:high_mark - low_mark]
  131
+            results = results[low_mark:high_mark - low_mark]
134 132
 
135  
-        for hit in hits:
136  
-            entity = hit["_source"]
137  
-            entity['id'] = hit['_id']
  133
+        for hit in results:
  134
+            entity = hit.get_data()
  135
+            entity['id'] = hit.meta.id
138 136
             yield entity
139 137
 
140 138
     @safe_call
@@ -176,9 +174,9 @@ def add_filter(self, column, lookup_type, negated, db_type, value):
176 174
         queryf = self._get_query_type(column, lookup_type, db_type, value)
177 175
 
178 176
         if negated:
179  
-            self.db_query.add(NotFilter(queryf))
  177
+            self.db_query.add([NotFilter(queryf)])
180 178
         else:
181  
-            self.db_query.add(queryf)
  179
+            self.db_query.add([queryf])
182 180
 
183 181
     def _get_query_type(self, column, lookup_type, db_type, value):
184 182
         if db_type == "unicode":
@@ -221,7 +219,7 @@ def _get_results(self):
221 219
         if self._ordering:
222 220
             query.sort = self._ordering
223 221
         #print "query", self.query.tables, query
224  
-        return self._connection.search(query, indexes=[self.connection.db_name], doc_types=self.query.model._meta.db_table)
  222
+        return self._connection.search(query, indices=[self.connection.db_name], doc_types=self.query.model._meta.db_table)
225 223
 
226 224
 class SQLCompiler(NonrelCompiler):
227 225
     """
2  django_elasticsearch/creation.py
@@ -48,7 +48,7 @@ def sql_indexes_for_model(self, model, style):
48 48
     def sql_create_model(self, model, style, known_models=set()):
49 49
         from mapping import model_to_mapping
50 50
         mappings = model_to_mapping(model)
51  
-        self.connection.db_connection.put_mapping(model._meta.db_table, mappings)
  51
+        self.connection.db_connection.put_mapping(model._meta.db_table, {mappings.name:mappings.as_dict()})
52 52
         return [], {}
53 53
 
54 54
     def set_autocommit(self):
12  django_elasticsearch/manager.py
@@ -228,18 +228,6 @@ def values_list(self, *args, **kwargs):
228 228
             raise Exception("args len must be 1 when flat=True")
229 229
         
230 230
         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])
231  
-#                
232  
-#            if self._document._meta['geo_indexes'] and \
233  
-#               pymongo.version >= "1.5.1":
234  
-#                from pymongo import GEO2D
235  
-#                for index in self._document._meta['geo_indexes']:
236  
-#                    self._collection.ensure_index([(index, GEO2D)])
237  
-#            
238  
-#            # Ensure all needed field indexes are created
239  
-#            for field_name, field_instance in self._document._fields.iteritems():
240  
-#                if field_instance.__class__.__name__ == 'GeoLocationField':
241  
-#                    self._collection.ensure_index([(field_name, pymongo.GEO2D),])
242  
-#        return self._collection_obj
243 231
 
244 232
     @property
245 233
     def _cursor(self):
16  django_elasticsearch/operations.py
... ...
@@ -1,16 +0,0 @@
1  
-from djangotoolbox.db.base import NonrelDatabaseOperations
2  
-
3  
-class DatabaseOperations(NonrelDatabaseOperations):
4  
-    compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'
5  
-
6  
-    def sql_flush(self, style, tables, sequence_list):
7  
-        for table in tables:
8  
-            self.connection.db_connection.delete_mapping(self.connection.db_name, table)
9  
-        return []
10  
-
11  
-    def check_aggregate_support(self, aggregate):
12  
-        """
13  
-        This function is meant to raise exception if backend does
14  
-        not support aggregation.
15  
-        """
16  
-        pass
3  django_elasticsearch/south.py
... ...
@@ -1,6 +1,3 @@
1  
-import inspect
2  
-import re
3  
-    
4 1
 class DatabaseOperations(object):
5 2
     """
6 3
     ES implementation of database operations.
9  tests/testproj/manage.py
@@ -2,11 +2,10 @@
2 2
 import os, sys
3 3
 from django.core.management import execute_manager
4 4
 # dirty hack to get the backend working.
5  
-sys.path.insert(0, os.path.abspath('./..'))
6  
-sys.path.insert(0, os.path.abspath('./../..'))
7  
-example_dir = os.path.dirname(__file__)
8  
-sys.path.insert(0, os.path.join(example_dir, '..'))
9  
-
  5
+#sys.path.insert(0, os.path.abspath('./..'))
  6
+#sys.path.insert(0, os.path.abspath('./../..'))
  7
+#example_dir = os.path.dirname(__file__)
  8
+#sys.path.insert(0, os.path.join(example_dir, '..'))
10 9
 try:
11 10
     import settings # Assumed to be in the same directory.
12 11
 except ImportError:
6  tests/testproj/settings.py
@@ -24,7 +24,7 @@
24 24
         'USER': '',
25 25
         'PASSWORD': '',
26 26
         'HOST': 'localhost',
27  
-        'PORT': '9500',
  27
+        'PORT': '9200',
28 28
         'SUPPORTS_TRANSACTIONS': False,
29 29
     },
30 30
 }
@@ -100,7 +100,7 @@
100 100
     'django.contrib.messages',
101 101
     'testproj.myapp',
102 102
     'testproj.mixed',
103  
-    'south',
  103
+    #'south',
104 104
     # Uncomment the next line to enable the admin:
105 105
     'django.contrib.admin',
106 106
 )
@@ -109,4 +109,4 @@
109 109
 ELASTICSEARCH_MANAGED_APPS = ['testproj.myapp', ]
110 110
 ELASTICSEARCH_MANAGED_MODELS = ['mixed.record', ]
111 111
 
112  
-SOUTH_DATABASE_ADAPTERS = { "default" : "django_elasticsearch.south"}
  112
+#SOUTH_DATABASE_ADAPTERS = { "default" : "django_elasticsearch.south"}

0 notes on commit 8fd25bd

Please sign in to comment.
Something went wrong with that request. Please try again.