def test_matches_replies_of_replies_to_an_annotation(self, Annotation, search): ann1 = Annotation() # Create a reply on ann1 and a reply to the reply. reply1 = Annotation(references=[ann1.id]) reply2 = Annotation(references=[ann1.id, reply1.id]) expected_reply_ids = [reply1.id, reply2.id] ann_ids = [ann1.id] search.append_modifier(query.RepliesMatcher(ann_ids)) result = search.run(webob.multidict.MultiDict({})) assert sorted(result.annotation_ids) == sorted(expected_reply_ids)
def test_matches_unnested_replies_to_annotations(self, Annotation, search): ann1 = Annotation() ann2 = Annotation() ann3 = Annotation() Annotation() # Create two replies on ann1. reply1 = Annotation(references=[ann1.id]) reply2 = Annotation(references=[ann1.id]) # Create a reply on ann2 reply3 = Annotation(references=[ann2.id]) # Create a reply on ann3 Annotation(references=[ann3.id]) expected_reply_ids = [reply1.id, reply2.id, reply3.id] ann_ids = [ann1.id, ann2.id] search.append_modifier(query.RepliesMatcher(ann_ids)) result = search.run(webob.multidict.MultiDict({})) assert sorted(result.annotation_ids) == sorted(expected_reply_ids)
def search_replies(self, annotation_ids): if not self.separate_replies: return [] self.reply_builder.append_matcher(query.RepliesMatcher(annotation_ids)) response = None with self._instrument(): response = self.es.conn.search(index=self.es.index, doc_type=self.es.t.annotation, _source=False, body=self.reply_builder.build({'limit': 200})) if len(response['hits']['hits']) < response['hits']['total']: log.warn("The number of reply annotations exceeded the page size " "of the Elasticsearch query. We currently don't handle " "this, our search API doesn't support pagination of the " "reply set.") return [hit['_id'] for hit in response['hits']['hits']]
def _search_replies(self, annotation_ids): if not self.separate_replies: return [] # The only difference between a search for annotations and a search for # replies to annotations is the RepliesMatcher and the params passed to # the modifiers. response = self._search( [query.RepliesMatcher(annotation_ids)] + self._modifiers, [], # Aggregations aren't used in replies. MultiDict({"limit": self._replies_limit}), ) if len(response["hits"]["hits"]) < response["hits"]["total"]: log.warning( "The number of reply annotations exceeded the page size " "of the Elasticsearch query. We currently don't handle " "this, our search API doesn't support pagination of the " "reply set.") return [hit["_id"] for hit in response["hits"]["hits"]]