예제 #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"))
예제 #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"))
예제 #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"))
예제 #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")
     )
예제 #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")
     )
예제 #6
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")
     )
예제 #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"))
예제 #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")
     )
예제 #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]")
     )
예제 #10
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")
     )
예제 #11
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"))
예제 #12
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")
        )
예제 #13
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")
        )
예제 #14
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"))
예제 #15
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")
     )
예제 #16
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]"))
예제 #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]"))
예제 #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")
     )
예제 #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")
     )
예제 #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")
     )
예제 #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]")
     )
예제 #22
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)
예제 #23
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")
     )
예제 #24
0
    def test_simple_q_fields(self):
        s = Search(q='dress', fields=['images'])
        with self.engine(s) as r:
            keys_found = set()
            for h in r.hits:
                keys_found.update(h.keys())

            self.assertEquals(len(keys_found), 1)
            self.assert_('images' in keys_found,
                         "field 'images' not in returned results")
예제 #25
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!")
예제 #26
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))
예제 #27
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')
예제 #28
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)
예제 #29
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"))
예제 #30
0
 def test_simple_search_1(self):
     s = Search(q="", num=10)
     self.assertEquals(s.build(), "products/search?q=&num=10")
예제 #31
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"))
예제 #32
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"))
예제 #33
0
 def test_error(self):
     s = Search(fields=['ponies'])
     with self.assertRaises(IOError):
         with self.engine(s) as r:
             self.fail("should never get here")
예제 #34
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"))
예제 #35
0
 def test_simple_search_1(self):
     s = Search(q="", num=10)
     self.assertEquals(s.build(), "products/search?q=&num=10")
예제 #36
0
 def test_simple_q(self):
     s = Search(q='dress')
     with self.engine(s) as r:
         self.assertEquals(r.hits.numFound, 1)
         self.assertEquals(r.hits[0]['id'],
                           '111f49eacc7dbc9ab2df53f8ce52ec64')
예제 #37
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']))
예제 #38
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")
예제 #39
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")
예제 #40
0
 def test_simple_search(self):
     s = Search(q="shirt")
     self.assertEquals(s.build(), "products/search?q=shirt")
예제 #41
0
 def test_simple_search(self):
     s = Search(q="shirt")
     self.assertEquals(s.build(), "products/search?q=shirt")
예제 #42
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"))
예제 #43
0
 def test_sort(self):
     s = Search(q='', sort=S.asc('price'), fields=['price'])
     with self.engine(s) as r:
         self.assertEquals(r.hits.numFound, 5)
         self.assertEquals(r.hits[0]['price'], '59.0 USD')
         self.assertEquals(r.hits[-1]['price'], '178.0 USD')
예제 #44
0
# 1.
from merlin import Merlin

engine = Merlin(company='my_company',
                environment='prod',
                instance='my_instance')

# 2.
from merlin.search import Search

with engine(Search(q="dress")) as results:
    print results

# 3. A query where we want 50 results starting from the 100th result
s = Search(q="red dress", start=100, num=50)

with engine(s) as results:
    print results

# 4. A query where we only want back the "id" and "title" fields
s = Search(q="red dress", fields=["id", "title"])

with engine(s) as results:
    print results

# 5. Get all fields including debug fields
s = Search(q='red dress', fields=['[debug]'])

with engine(s) as results:
    print results
예제 #45
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"))