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_ESRange_equality(self): self.assertEqual(RangeQuery(), RangeQuery()) self.assertEqual(RangeQuery(ESRange("foo", 1, 2)), RangeQuery(ESRange("foo", 1, 2))) self.assertNotEquals(RangeQuery(ESRange("foo", 1, 2)), RangeQuery(ESRange("bar", 1, 2))) self.assertEqual(RangeFilter(), RangeFilter()) self.assertEqual(RangeFilter(ESRange("foo", 1, 2)), RangeFilter(ESRange("foo", 1, 2))) self.assertNotEquals(RangeFilter(ESRange("foo", 1, 2)), RangeFilter(ESRange("bar", 1, 2))) self.assertEqual(ESRange("foo"), ESRange("foo")) self.assertNotEquals(ESRange("foo"), ESRange("bar")) self.assertEqual(ESRange("foo", 1), ESRange("foo", 1)) self.assertNotEquals(ESRange("foo", 1), ESRange("foo", 2)) self.assertEqual(ESRange("foo", 1, 2), ESRange("foo", 1, 2)) self.assertNotEquals(ESRange("foo", 1, 2), ESRange("foo", 1, 3)) self.assertEqual(ESRange("foo", 1, 2, True, False), ESRange("foo", 1, 2, True, False)) self.assertNotEquals(ESRange("foo", 1, 2, True, False), ESRange("foo", 1, 2, False, True)) self.assertEqual(ESRangeOp("foo", "gt", 5), ESRangeOp("foo", "gt", 5)) self.assertEqual(ESRangeOp("bar", "lt", 6), ESRangeOp("bar", "lt", 6)) self.assertEqual(ESRangeOp("bar", "gt", 3, "lt", 6), ESRangeOp("bar", "lt", 6, "gt", 3))
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}])