-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebsite.py
65 lines (51 loc) · 1.71 KB
/
website.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
'''
website
:copyright: (c) 2014-2015 by Openlabs Technologies & Consulting (P) Ltd.
:license: GPLv3, see LICENSE for more details
'''
from trytond.pool import Pool, PoolMeta
from nereid import request, route, render_template
from pagination import ElasticPagination
__metaclass__ = PoolMeta
__all__ = ['Website']
class Website:
"Nereid Website"
__name__ = 'nereid.website'
@classmethod
def auto_complete(cls, phrase):
"""
This is a downstream implementation which uses elasticsearch to return
results for a query.
"""
Product = Pool().get('product.product')
return Product._es_autocomplete(phrase)
@classmethod
@route('/search')
def quick_search(cls):
"""
This version of quick_search uses elasticsearch to build
search results for searches from the website.
"""
Product = Pool().get('product.product')
page = request.args.get('page', 1, type=int)
phrase = request.args.get('q', '')
logger = Pool().get('elasticsearch.configuration').get_logger()
search_obj = Product._quick_search_es(phrase)
products = ElasticPagination(
Product.__name__, search_obj, page, Product.per_page
)
if products:
logger.info(
"Search for %s yielded in %d results." %
(phrase, products.count)
)
else:
logger.info(
"Search for %s yielded no results from elasticsearch." % phrase
)
return render_template(
'search-results.jinja',
products=products,
facets=products.result_set.facets
)