Skip to content

Commit

Permalink
API Breakage: DeleteByQuery renamed to delete_by_query to be API name…
Browse files Browse the repository at this point in the history
… compatibile
  • Loading branch information
Alberto Paro committed Feb 20, 2012
1 parent 554d165 commit 46102fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ v. 0.16.0:

Add ScriptFields object used as parameter script_fields of Search object (aguereca).

Add IdsQuery, IdsFilter and deleteByQuery (aguereca).
Add IdsQuery, IdsFilter and delete_by_query (aguereca).

Bulk delete (acdha).

Expand Down
4 changes: 2 additions & 2 deletions pyes/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def delete(self, index, doc_type, id, bulk=False, querystring_args=None):
path = self._make_path([index, doc_type, id])
return self._send_request('DELETE', path, params=querystring_args)

def deleteByQuery(self, indices, doc_types, query, **request_params):
def delete_by_query(self, indices, doc_types, query, **request_params):
"""
Delete documents from one or more indices and one or more types based on a query.
"""
Expand All @@ -1157,7 +1157,7 @@ def deleteByQuery(self, indices, doc_types, query, **request_params):
# A direct set of search parameters.
body = json.dumps(query, cls=self.encoder)
else:
raise InvalidQuery("deleteByQuery() must be supplied with a Query object, or a dict")
raise InvalidQuery("delete_by_query() must be supplied with a Query object, or a dict")

path = self._make_path([','.join(indices), ','.join(doc_types), '_query'])
return self._send_request('DELETE', path, body, querystring_args)
Expand Down
19 changes: 13 additions & 6 deletions pyes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self,
self.fields = fields
self.start = start
self.size = size
self.highlight = highlight
self._highlight = highlight
self.sort = sort
self.explain = explain
self.facet = facet or FacetFactory()
Expand All @@ -115,6 +115,7 @@ def __init__(self,
self.index_boost = index_boost
self.min_score = min_score
self.stats = stats
self.bulk_read = bulk_read

def get_facet_factory(self):
"""
Expand All @@ -141,8 +142,8 @@ def serialize(self):
res['size'] = self.size
if self.start is not None:
res['from'] = self.start
if self.highlight:
res['highlight'] = self.highlight.serialize()
if self._highlight:
res['highlight'] = self._highlight.serialize()
if self.sort:
res['sort'] = self.sort
if self.explain:
Expand All @@ -166,16 +167,22 @@ def serialize(self):
res['stats'] = self.stats
return res

@property
def highlight(self):
if self._highlight is None:
self._highlight = HighLighter("<b>", "</b>")
return self._highlight

def add_highlight(self, field, fragment_size=None,
number_of_fragments=None, fragment_offset=None):
"""Add a highlight field.
The Search object will be returned, so calls to this can be chained.
"""
if self.highlight is None:
self.highlight = HighLighter("<b>", "</b>")
self.highlight.add_field(field, fragment_size, number_of_fragments, fragment_offset)
if self._highlight is None:
self._highlight = HighLighter("<b>", "</b>")
self._highlight.add_field(field, fragment_size, number_of_fragments, fragment_offset)
return self

def add_index_boost(self, index, boost):
Expand Down

0 comments on commit 46102fa

Please sign in to comment.