Example #1
0
 def test_hist_facet(self):
     s = Search(
         facets=F.hist('price', start=0, end=100, gap=50)
     )
     with self.engine(s) as r:
         res = set(r.facets.histograms['price'].items())
         wanted = set([(('0.0', '50.0'), 0), (('50.0', '100.0'), 4)])
         self.assertEquals(res, wanted)
Example #2
0
 def test_hist_facet(self):
     s = Search(
         q = "shirt",
         facets = F.hist("price", start=10, end=100, gap=5, key='prices')
     )
     self.assertEquals(s.build(), 
         "products/search?q=shirt&facet=" + 
         enc("field=price/type=hist/key=prices/range=[10:100:5]")
     )
Example #3
0
 def test_multiple_facets(self):
     s = Search(q="shirt",
                facets=[
                    F.enum('brand', num=10, key='top_brands'),
                    F.hist('price', start=0, end=100, gap=10)
                ])
     self.assertEquals(
         s.build(), "products/search?q=shirt" + '&facet=' +
         enc("field=brand/type=enum/key=top_brands/num=10") + '&facet=' +
         enc("field=price/type=hist/range=[0:100:10]"))
Example #4
0
 def test_hist_facet(self):
     s = Search(q="shirt",
                facets=F.hist("price",
                              start=10,
                              end=100,
                              gap=5,
                              key='prices'))
     self.assertEquals(
         s.build(), "products/search?q=shirt&facet=" +
         enc("field=price/type=hist/key=prices/range=[10:100:5]"))
Example #5
0
 def test_multiple_facets(self):
     s = Search(
         q = "shirt",
         facets = [
             F.enum('brand', num=10, key='top_brands'),
             F.hist('price', start=0, end=100, gap=10)
         ]
     )
     self.assertEquals(s.build(), 
         "products/search?q=shirt" + 
         '&facet=' + enc("field=brand/type=enum/key=top_brands/num=10") +
         '&facet=' + enc("field=price/type=hist/range=[0:100:10]")
     )
Example #6
0
    print results.facets.enums

# 12. A query where we want red dresses and the range of prices returned
s = Search(
    q      = 'red dress',
    facets = F.range('price')
)

with engine(s) as results:
    print results.facets.ranges

# 13. A query where we want red dresses and a histogram of their 
# price fields from 0-500 in increments of 100.
s = Search(
    q      = 'red dress',
    facets = F.hist('price', start=0, end=500, gap=100)
)

with engine(s) as results:
    print results.facets.histograms

# 14. A search with multiple keyed facets on the 'brand' field
s = Search(
    q      = 'red dress',
    facets = [
        F.range('price', tag="price_range"),
        F.hist('price', start=0, end=500, gap=100, tag='price_hist')
    ]
)

with engine(s) as results:
Example #7
0
 def test_hist_facet(self):
     s = Search(facets=F.hist('price', start=0, end=100, gap=50))
     with self.engine(s) as r:
         res = set(r.facets.histograms['price'].items())
         wanted = set([(('0.0', '50.0'), 0), (('50.0', '100.0'), 4)])
         self.assertEquals(res, wanted)
Example #8
0
s = Search(q='red dress',
           filter=NF.cnf(Field('price') < 100),
           facet=F.enum('brand', num=5))

with engine(s) as results:
    print results.facets.enums

# 12. A query where we want red dresses and the range of prices returned
s = Search(q='red dress', facets=F.range('price'))

with engine(s) as results:
    print results.facets.ranges

# 13. A query where we want red dresses and a histogram of their
# price fields from 0-500 in increments of 100.
s = Search(q='red dress', facets=F.hist('price', start=0, end=500, gap=100))

with engine(s) as results:
    print results.facets.histograms

# 14. A search with multiple keyed facets on the 'brand' field
s = Search(q='red dress',
           facets=[
               F.range('price', tag="price_range"),
               F.hist('price', start=0, end=500, gap=100, tag='price_hist')
           ])

with engine(s) as results:
    print results.facets

# 15. pass array of tags to exclude into the facet