1 | import xappy
|
---|
2 |
|
---|
3 | prices = ['11.95', '14.50', '60.00']
|
---|
4 |
|
---|
5 | iconn = xappy.IndexerConnection('db1')
|
---|
6 | iconn.add_field_action('price', xappy.FieldActions.FACET, type='float')
|
---|
7 |
|
---|
8 | for index, price in enumerate(prices):
|
---|
9 | doc = xappy.UnprocessedDocument(id=str(index))
|
---|
10 | doc.fields.append(xappy.Field('price', price))
|
---|
11 | iconn.replace(doc)
|
---|
12 |
|
---|
13 | del iconn
|
---|
14 |
|
---|
15 | sconn = xappy.SearchConnection('db1')
|
---|
16 | results = sconn.search(sconn.query_all(), 1, 1000, getfacets=True, allowfacets=['price'])
|
---|
17 |
|
---|
18 | s = results.get_suggested_facets(maxfacets=1, required_facets=['price'],
|
---|
19 | desired_num_of_categories=1000)
|
---|
20 |
|
---|
21 | # this should print 3 facets
|
---|
22 | print s[0][1]
|
---|