Commits

Benoit C  committed 31c6a09

bulk indexing

  • Participants
  • Parent commits 7d62a0c

Comments (0)

Files changed (1)

File backend/elasticsearch_backend.py

         self.mapping = self.build_schema(self.site.all_searchfields())
 
     def update(self, index, iterable):
+        print "update"
         
         try:
             self.conn.create_index(self.index_name)
         docs = []
         for obj in iterable:
             doc = index.full_prepare(obj)
-            self.conn.index(doc, self.index_name, self.mapping, int(doc.get('django_id')), bulk=True))
+            self.conn.index(doc, self.index_name, self.mapping_name, int(doc.get('django_id')), bulk=True)
             
         self.conn.refresh([self.index_name])
 
 
     def remove(self, obj_or_string):
-        result = self.conn.delete(self.index_name,"test-index", self.mapping_name, 1)
+        print "remove"
+        result = self.conn.delete(self.index_name, self.mapping_name, obj.id)
 
     def clear(self, models=[]):
         print "clear"
         pass
 
 class SearchQuery(BaseSearchQuery):
+    def __init__(self, site=None, backend=None):
+        super(SearchQuery, self).__init__(backend=backend)
+        
+        if backend is not None:
+            self.backend = backend
+        else:
+            self.backend = SearchBackend(site=site)
 
     def build_query_fragment(self, field, filter_type, value):
         print "build_query_fragment"
-        pass
+        print field
+        print filter_type
+
+        filter_types = {
+                'exact': pyes.TermQuery(field, value),
+                'gt': "%s:{%s TO}",
+                'gte': "%s:[%s TO]",
+                'lt': "%s:{TO %s}",
+                'lte': "%s:[TO %s]",
+                'startswith': "%s:%s*",
+            }
+        return ''#filter_types[filter_type]
 
     def build_query(self):
+        
+        query = self.query_filter
+        print query
+
+
         print "build_query"
+        query = self.build_query_fragment
+        return query
+
         pass
 
     def build_params(self):
         pass
 
     def run(self, spelling_query=None):
-        print "run"
-        pass
+        final_query = self.build_query()
+        final_query = pyes.StringQuery("*")
+        results = self.backend.conn.search(query=final_query, indexes=[self.backend.index_name])
+        print results
+        print type(results)
 
-    def run_mlt(self):
-        print "run_mlt"
-        pass
+        self._results = results.get('results', [])
+        self._hit_count = results.get('hits', 0)
+        self._facet_counts = self.post_process_facets(results)
+        self._spelling_suggestion = results.get('spelling_suggestion', None)
+
+    # def run_mlt(self):
+    #     print "run_mlt"
+    #     pass
 
     def run_raw(self):
         print "run_raw"
         pass
 
-    def get_count(self):
-        print "get_count"
-        pass
+    # def get_count(self):
+    #     print "get_count"
+    #     pass
 
-    def get_results(self):
-        print "get_results"
-        pass
+    # def get_results(self):
+    #     print "get_results"
+    #     pass
 
-    def get_facet_counts(self):
-        print "get_facet_counts"
-        pass
+    # def get_facet_counts(self):
+    #     print "get_facet_counts"
+    #     pass
 
-    def boost_fragment(self, boost_word, boost_value):
-        print "boost_fragment"
-        pass
+    # def boost_fragment(self, boost_word, boost_value):
+    #     print "boost_fragment"
+    #     pass
 
-    def matching_all_fragment(self):
-        print "matching_all_fragment"
-        pass
+    # def matching_all_fragment(self):
+    #     print "matching_all_fragment"
+    #     pass
 
-    def add_filter(self, expression, value, use_not=False, use_or=False):
-        print "add_filter"
-        pass
 
-    def add_order_by(self, field):
-        print "add_order_by"
-        pass
+    # def add_order_by(self, field):
+    #     print "add_order_by"
+    #     pass
 
-    def clear_order_by(self):
-        print "clear_order_by"
-        pass
+    # def clear_order_by(self):
+    #     print "clear_order_by"
+    #     pass
 
-    def add_model(self, model):
-        print "add_model"
-        pass
+    # def add_model(self, model):
+    #     print "add_model"
+    #     pass
     
-    def set_limits(self, low=None, high=None):
-        print "set_limits"
-        pass
+    # def set_limits(self, low=None, high=None):
+    #     print "set_limits"
+    #     pass
     
-    def clear_limits(self):
-        print "clear_limits"
-        pass
+    # def clear_limits(self):
+    #     print "clear_limits"
+    #     pass
 
-    def add_boost(self, term, boost_value):
-        print "add_boost"
-        pass
+    # def add_boost(self, term, boost_value):
+    #     print term
+    #     print boost_value
+    #     print "add_boost"
+    #     pass
 
-    def raw_search(self, query_string, **kwargs):
-        print "raw_search"
-        pass
+    # def raw_search(self, query_string, **kwargs):
+    #     print "raw_search"
+    #     pass
 
-    def more_like_this(self, model_instance):
-        print "more_like_this"
-        pass
+    # def more_like_this(self, model_instance):
+    #     print "more_like_this"
+    #     pass
 
-    def add_highlight(self):
-        print "add_highlight"
-        pass
+    # def add_highlight(self):
+    #     print "add_highlight"
+    #     pass
 
-    def add_field_facet(self, field):
-        print "add_field_facet"
-        pass
+    # def add_field_facet(self, field):
+    #     print "add_field_facet"
+    #     pass
 
-    def add_date_facet(self, field, start_date, end_date, gap_by, gap_amount):
-        print "add_date_facet"
-        pass
+    # def add_date_facet(self, field, start_date, end_date, gap_by, gap_amount):
+    #     print "add_date_facet"
+    #     pass
     
-    def add_query_facet(self, field, query):
-        print "add_query_facet"
-        pass
+    # def add_query_facet(self, field, query):
+    #     print "add_query_facet"
+    #     pass
 
-    def add_narrow_query(self, query):
-        print "add_narrow_query"
-        pass
+    # def add_narrow_query(self, query):
+    #     print "add_narrow_query"
+    #     pass