Пример #1
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"))
Пример #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]"))
Пример #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]")
     )
Пример #4
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"))
Пример #5
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"))
Пример #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")
     )
Пример #7
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"))
Пример #8
0
 def testUploadUrl(self):
     noops = [Add(), Update(), Delete()]
     for noop, ep in zip(noops, ['add', 'update', 'delete']):
         res = self.uploader(noop)
         self.assertEquals(res._build_url(),
             "https://upload-dev.search.blackbird.am/%s?" % ep +
             "user="******"*****@*****.**") + "&token=123&company_id=blackbird&env=dev&"\
             "instance_name=client_test")
Пример #9
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")
     )
Пример #10
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"))
Пример #11
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")
     )
Пример #12
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")
     )
Пример #13
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")
     )
Пример #14
0
 def test_fields(self):
     s = Vrec(
         id = "asdf235",
         fields=["one", "two", "three"]
     )
     self.assertEquals(s.build(), 
         "products/vrec?id=asdf235" + 
         '&fields=' + enc("one,two,three")
     )
Пример #15
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")
     )
Пример #16
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]")
     )
Пример #17
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")
        )
Пример #18
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]"))
Пример #19
0
    def test_mode(self):
        make_s = lambda m: Search(q='hoodie', mode=m)
        for m in ('semantic', 'keyword'):
            self.assertEquals(
                make_s(m).build(),
                "products/search?q=hoodie" + '&mode=' + enc(m))

        with self.assertRaises(ValidationError):
            make_s('foo').build()
            self.fail("Should have failed!")
Пример #20
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"))
Пример #21
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")
     )
Пример #22
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")
        )
Пример #23
0
    def test_mode(self):
        make_s = lambda m: Search(q='hoodie', mode=m)
        for m in ('semantic', 'keyword'):
            self.assertEquals(make_s(m).build(),
                "products/search?q=hoodie" +
                '&mode=' + enc(m)
            )

        with self.assertRaises(ValidationError):
            make_s('foo').build()
            self.fail("Should have failed!")
Пример #24
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")
     )
Пример #25
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")
     )
Пример #26
0
 def testUploadUrl(self):
     noops = [Add(), Update(), Delete()]
     for noop, ep in zip(noops, ["add", "update", "delete"]):
         res = self.uploader(noop)
         self.assertEquals(
             res._build_url(),
             "https://upload-dev.search.blackbird.am/%s?" % ep
             + "user="******"*****@*****.**")
             + "&token=123&company_id=blackbird&env=dev&"
             "instance_name=client_test",
         )
Пример #27
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")
     )
Пример #28
0
 def __getitem__(self, key):
   return urllib2.urlopen('%s?action=get&key=%s'%(self.url, enc(key))).read()
Пример #29
0
 def __getitem__(self, key):
   return urllib2.urlopen('%s?action=get&key=%s'%(self.url, enc(key))).read()
Пример #30
0
 def __delitem__(self, key):
   urllib2.urlopen('%s?action=unset&key=%s'%(self.url, enc(key)))
Пример #31
0
 def __delitem__(self, key):
   urllib2.urlopen('%s?action=unset&key=%s'%(self.url, enc(key)))
Пример #32
0
 def __setitem__(self, key, value):
   urllib2.urlopen('%s?action=set&key=%s&value=%s'%(self.url, enc(key), enc(value)))
Пример #33
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"))
Пример #34
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"))
Пример #35
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"))
Пример #36
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"))
Пример #37
0
 def __setitem__(self, key, value):
   urllib2.urlopen('%s?action=set&key=%s&value=%s'%(self.url, enc(key), enc(value)))
Пример #38
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"))
Пример #39
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"))