예제 #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_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)
예제 #3
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")
     )
예제 #4
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"))
예제 #5
0
    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)
예제 #6
0
 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')
예제 #7
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")
     )
예제 #8
0
 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']))
예제 #9
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"))
예제 #10
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")
     )
예제 #11
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")
     )
예제 #12
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")
     )
예제 #13
0
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))
예제 #14
0
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",
예제 #15
0
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:
예제 #16
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"))
예제 #17
0
 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']))
예제 #18
0
 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')
예제 #19
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"))