Esempio n. 1
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]"))
Esempio n. 2
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]")
     )
Esempio n. 3
0
 def test_enum_facet_named(self):
     s = Search(
         q = "shirt",
         facets = F.enum("brand", num=10, key='ponies')
     )
     self.assertEquals(s.build(), 
         "products/search?q=shirt&facet=" + enc("field=brand/type=enum/key=ponies/num=10")
     )
Esempio n. 4
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)
Esempio n. 5
0
 def test_range_facet(self):
     s = Search(
         q = "shirt",
         facets = F.range("price", key='prices')
     )
     self.assertEquals(s.build(), 
         "products/search?q=shirt&facet=" + 
         enc("field=price/type=range/key=prices")
     )
Esempio n. 6
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]")
     )
Esempio n. 7
0
 def test_enum_facet_excluding(self):
     s = Search(
         q = "shirt",
         facets = F.enum("brand", num=10, key='ponies', exclude=['foo', 'bar'])
     )
     self.assertEquals(s.build(), 
         "products/search?q=shirt&facet=" + 
         enc("field=brand/type=enum/key=ponies/num=10/ex=foo,bar")
     )
Esempio n. 8
0
 def test_enum_facet_excluding(self):
     s = Search(q="shirt",
                facets=F.enum("brand",
                              num=10,
                              key='ponies',
                              exclude=['foo', 'bar']))
     self.assertEquals(
         s.build(), "products/search?q=shirt&facet=" +
         enc("field=brand/type=enum/key=ponies/num=10/ex=foo,bar"))
Esempio n. 9
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]"))
Esempio n. 10
0
    filter = NF.cnf(
        (Field("size") == ('S', 'M')),
        tag="smallormedium"
    )
)

with engine(s) as results:
    print results

# 11. A query where we want red dresses under $100 
# and the top 5 brands returned as facets
from merlin.facet import Facet as F
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 
Esempio n. 11
0
 def test_range_facet(self):
     s = Search(q="shirt", facets=F.range("price", key='prices'))
     self.assertEquals(
         s.build(), "products/search?q=shirt&facet=" +
         enc("field=price/type=range/key=prices"))
Esempio n. 12
0
 def test_enum_facet_named(self):
     s = Search(q="shirt", facets=F.enum("brand", num=10, key='ponies'))
     self.assertEquals(
         s.build(), "products/search?q=shirt&facet=" +
         enc("field=brand/type=enum/key=ponies/num=10"))
Esempio n. 13
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)
Esempio n. 14
0
# 10. A query where we want red dresses in size 'S' or in size 'M' and
# tag it as 'smallormedium'
s = Search(q="red dress",
           filter=NF.cnf((Field("size") == ('S', 'M')), tag="smallormedium"))

with engine(s) as results:
    print results

# 11. A query where we want red dresses under $100
# and the top 5 brands returned as facets
from merlin.facet import Facet as F

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: