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"))
def test_and_search(self): s = Search(q='', filter=NF.cnf((Field('colors') == 'Red') & (Field('price') < 178))) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 1) self.assertEquals(r.hits[0]['brand'], 'Raoul') s = Search(q='', filter=NF.cnf((Field('colors') == 'Red') & (Field('price') <= 178))) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 2)
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") )
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"))
def test_and_search(self): s = Search(q='', filter=NF.cnf( (Field('colors') == 'Red') & (Field('price') < 178) ) ) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 1) self.assertEquals(r.hits[0]['brand'], 'Raoul') s = Search(q='', filter=NF.cnf( (Field('colors') == 'Red') & (Field('price') <= 178) ) ) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 2)
def test_price_filter(self): s = Search(q='', filter=NF.cnf(Field('price') > 150), fields=['price'] ) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 1) self.assertEquals(r.hits[0]['price'], '178.0 USD')
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") )
def test_or_search(self): s = Search(q='', filter=NF.cnf( Field('colors') == ('Red', 'Blue') ) ) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 3) for h in r.hits: self.assertIn(h['colors'][0], set(['Red', 'Blue', 'red']))
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"))
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") )
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") )
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") )
def read(args): company, env, instance = args.instance.split('.') engine = Merlin(company, env, instance, host=args.host, use_ssl=args.use_ssl) docs = args.docs if not args.inOrder else [[d] for d in args.docs] for docSet in docs: s = Search(filter=NF.cnf(Field('id') == docSet), fields=args.fields, index=args.index) with engine(s) as results: for hit in results.hits: print(pprint(hit))
s = Search(q='red dress', sort=S.asc('price')) with engine(s) as results: print results # 7. s = Search(q='red dress', sort=[S.asc('price'), S.desc('size')]) with engine(s) as results: print results # 8. from merlin.filter import NF, Field s = Search(q='red dress', filter=NF.cnf(Field('price') < 100)) with engine(s) as results: print results # 9. s = Search(q="red dress", filter=NF.cnf((Field('size') == ('S', 'M')) & (Field('price') < 100))) with engine(s) as results: print results # 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",
with engine(s) as results: print results # 7. s = Search(q='red dress', sort = [S.asc('price'), S.desc('size')]) with engine(s) as results: print results # 8. from merlin.filter import NF, Field s = Search( q = 'red dress', filter = NF.cnf( Field('price') < 100 ) ) with engine(s) as results: print results # 9. s = Search( q = "red dress", filter = NF.cnf( (Field('size') == ('S', 'M')) & (Field('price') < 100) ) ) with engine(s) as results:
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"))
def test_or_search(self): s = Search(q='', filter=NF.cnf(Field('colors') == ('Red', 'Blue'))) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 3) for h in r.hits: self.assertIn(h['colors'][0], set(['Red', 'Blue', 'red']))
def test_price_filter(self): s = Search(q='', filter=NF.cnf(Field('price') > 150), fields=['price']) with self.engine(s) as r: self.assertEquals(r.hits.numFound, 1) self.assertEquals(r.hits[0]['price'], '178.0 USD')
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"))