Exemplo n.º 1
0
    def test_group(self):
        s = Search(q='hoodie',
                   group=Group(field='category', num=10, sort=S.asc('price')))

        self.assertEquals(
            s.build(), "products/search?q=hoodie" + '&group=' +
            enc(r"field=category/sort=price:asc/num=10"))
Exemplo n.º 2
0
 def test_filter_tags(self):
     s = Search(filter=NF.cnf((Field('Color') == 'Red')
                              & (Field('Color') != 'Blue'),
                              tag="redandblue"))
     self.assertEquals(
         s.build(), "products/search?q=" + '&filter=' +
         enc(r"exp=Color:Red,Color:!Blue/type=cnf/tag=redandblue"))
Exemplo n.º 3
0
    def test_geo(self):
        s = Search(q='hoodie',
                   geo=Geo(field='geo', pt=(37.774929, -122.419416), dist=35))

        self.assertEquals(
            s.build(), "products/search?q=hoodie" + '&geo=' +
            enc(r"field=geo/pt=(37.774929,-122.419416)/d=35.000"))
Exemplo n.º 4
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")
     )
Exemplo n.º 5
0
 def test_fields(self):
     s = Search(
         q = "socks",
         fields=["one", "two", "three"]
     )
     self.assertEquals(s.build(), 
         "products/search?q=socks" + 
         '&fields=' + enc("one,two,three")
     )
Exemplo n.º 6
0
 def test_multi_filters(self):
     s = Search(filter=[
         NF.cnf((Field('Color') == 'Red') & (Field('Color') != 'Blue')),
         NF.dnf(Field('Price').between(0, 100))
     ])
     self.assertEquals(
         s.build(), "products/search?q=" + '&filter=' +
         enc(r"exp=Color:Red,Color:!Blue/type=cnf") + '&filter=' +
         enc(r"exp=Price:[0:100]/type=dnf"))
Exemplo 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"))
Exemplo n.º 8
0
 def test_single_filter(self):
     s = Search(
         q='hoodie',
         filter=NF.cnf(Field('price') <= 20)
     )
     self.assertEquals(s.build(), 
         "products/search?q=hoodie" + 
         '&filter=' + enc(r"exp=price:[:20]/type=cnf")
     )
Exemplo n.º 9
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")
     )
Exemplo n.º 10
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]")
     )
Exemplo 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")
     )
Exemplo n.º 12
0
 def test_filters(self):
     s = Search(
         filter=NF.cnf(
             (Field('Color') == 'Red') & (Field('Color') != 'Blue')
         )
     )
     self.assertEquals(s.build(), 
         "products/search?q=" + 
         '&filter=' + enc(r"exp=Color:Red,Color:!Blue/type=cnf")
     )
Exemplo n.º 13
0
 def test_multi_values(self):
     s = Search(
         filter=NF.cnf(
             (Field('Color') == ('Blue', 'Red')) & \
             (Field('Color') != ('Teal', 'Green'))
         )
     )
     self.assertEquals(
         s.build(), "products/search?q=" + "&filter=" +
         enc(r"exp=Color:Blue|Color:Red,Color:!Teal,Color:!Green/type=cnf"))
Exemplo n.º 14
0
    def test_group(self):
        s = Search(
            q='hoodie',
            group=Group(field='category', num=10, sort=S.asc('price'))
        )

        self.assertEquals(s.build(), 
            "products/search?q=hoodie" + 
            '&group=' + enc(r"field=category/sort=price:asc/num=10")
        )
Exemplo n.º 15
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]"))
Exemplo n.º 16
0
    def test_geo(self):
        s = Search(
            q='hoodie',
            geo=Geo(field='geo', pt=(37.774929, -122.419416), dist=35)
        )

        self.assertEquals(s.build(),
            "products/search?q=hoodie" +
            '&geo=' + enc(r"field=geo/pt=(37.774929,-122.419416)/d=35.000")
        )
Exemplo n.º 17
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]"))
Exemplo n.º 18
0
 def test_lt_gt_facet(self):
     s = Search(
         q='hoodie',
         filter=NF.cnf(
             (Field('price') < 20) & (Field('age') > 10)
         )
     )
     self.assertEquals(s.build(), 
         "products/search?q=hoodie" + 
         '&filter=' + enc(r"exp=price:[:20),age:(10:]/type=cnf")
     )
Exemplo n.º 19
0
 def test_multi_values(self):
     s = Search(
         filter=NF.cnf(
             (Field('Color') == ('Blue', 'Red')) & \
             (Field('Color') != ('Teal', 'Green'))
         )
     )
     self.assertEquals(s.build(),
         "products/search?q=" +
         "&filter=" + enc(r"exp=Color:Blue|Color:Red,Color:!Teal,Color:!Green/type=cnf")
     )
Exemplo n.º 20
0
 def test_sorting(self):
     s = Search(
         q = "pants",
         sort = [
             S.desc('brand'),
             S.asc('price')
         ]
     )
     self.assertEquals(s.build(), 
         "products/search?q=pants" + 
         '&sort=' + enc("brand:desc,price:asc")
     )
Exemplo n.º 21
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]")
     )
Exemplo n.º 22
0
 def test_multi_filters(self):
     s = Search(
         filter=[
             NF.cnf(
                 (Field('Color') == 'Red') & (Field('Color') != 'Blue')
             ),
             NF.dnf(
                 Field('Price').between(0, 100)
             )
         ]
     )
     self.assertEquals(s.build(), 
         "products/search?q=" + 
         '&filter=' + enc(r"exp=Color:Red,Color:!Blue/type=cnf") +
         '&filter=' + enc(r"exp=Price:[0:100]/type=dnf")
     )
Exemplo n.º 23
0
 def test_simple_search_2(self):
     s = Search(q="shirt", num=10, start=20)
     self.assertEquals(s.build(), "products/search?q=shirt&start=20&num=10")
Exemplo n.º 24
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"))
Exemplo n.º 25
0
 def test_single_filter(self):
     s = Search(q='hoodie', filter=NF.cnf(Field('price') <= 20))
     self.assertEquals(
         s.build(), "products/search?q=hoodie" + '&filter=' +
         enc(r"exp=price:[:20]/type=cnf"))
Exemplo n.º 26
0
 def test_simple_search_2(self):
     s = Search(q="shirt", num=10, start=20)
     self.assertEquals(s.build(), "products/search?q=shirt&start=20&num=10")
Exemplo n.º 27
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"))
Exemplo n.º 28
0
 def test_sorting(self):
     s = Search(q="pants", sort=[S.desc('brand'), S.asc('price')])
     self.assertEquals(
         s.build(),
         "products/search?q=pants" + '&sort=' + enc("brand:desc,price:asc"))
Exemplo n.º 29
0
 def test_simple_search_1(self):
     s = Search(q="", num=10)
     self.assertEquals(s.build(), "products/search?q=&num=10")
Exemplo n.º 30
0
 def test_fields(self):
     s = Search(q="socks", fields=["one", "two", "three"])
     self.assertEquals(
         s.build(),
         "products/search?q=socks" + '&fields=' + enc("one,two,three"))
Exemplo n.º 31
0
 def test_lt_gt_facet(self):
     s = Search(q='hoodie',
                filter=NF.cnf((Field('price') < 20) & (Field('age') > 10)))
     self.assertEquals(
         s.build(), "products/search?q=hoodie" + '&filter=' +
         enc(r"exp=price:[:20),age:(10:]/type=cnf"))
Exemplo n.º 32
0
 def test_simple_search_1(self):
     s = Search(q="", num=10)
     self.assertEquals(s.build(), "products/search?q=&num=10")
Exemplo n.º 33
0
 def test_simple_search(self):
     s = Search(q="shirt")
     self.assertEquals(s.build(), "products/search?q=shirt")
Exemplo n.º 34
0
 def test_simple_search(self):
     s = Search(q="shirt")
     self.assertEquals(s.build(), "products/search?q=shirt")