def query(cls, text): cls.ES.refresh() sub_filter = RangeFilter(qrange=ESRange('num_subscribers', 2)) logging.info("~FGSearch ~FCfeeds~FG by address: ~SB%s" % text) q = TextQuery('address', text) results = cls.ES.search(FilteredQuery(q, sub_filter), sort="num_subscribers:desc", size=5) if not results.total: logging.info("~FGSearch ~FCfeeds~FG by title: ~SB%s" % text) q = PrefixQuery('title', text) results = cls.ES.search(FilteredQuery(q, sub_filter), sort="num_subscribers:desc", size=5) if not results.total: logging.info("~FGSearch ~FCfeeds~FG by link: ~SB%s" % text) q = TextQuery('link.partial', text) results = cls.ES.search(FilteredQuery(q, sub_filter), sort="num_subscribers:desc", size=5) return results
def test_DateBefore1900(self): q = RangeQuery( ESRange("inserted", datetime(1, 1, 1), datetime(2, 1, 1))) resultset = self.conn.search(query=q, indices=self.index_name) self.assertEquals(resultset.total, 1) hit = resultset[0] self.assertEquals(hit.inserted, datetime(1, 1, 1, 0, 0, 0))
def test_date_facet_filter(self): q = MatchAllQuery() q = FilteredQuery(q, RangeFilter(qrange=ESRange('date', datetime.date(2011, 4, 1), datetime.date(2011, 5, 1), include_upper=False))) q = q.search() q.facet.facets.append(DateHistogramFacet('date_facet', field='date', interval='month')) resultset = self.conn.search(query=q, indices=self.index_name, doc_types=[self.document_type]) self.assertEquals(resultset.total, 2) self.assertEquals(resultset.facets['date_facet']['entries'], [{u'count': 2, u'time': 1301616000000}])