本文整理汇总了Python中trytond.pool.Pool.get_es_connection方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.get_es_connection方法的具体用法?Python Pool.get_es_connection怎么用?Python Pool.get_es_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.get_es_connection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _es_autocomplete
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def _es_autocomplete(cls, phrase):
"""
Handler for auto-completion via elastic-search.
The product's URL is generated here as request context is available
here. This is sent to the front-end for typeaheadJS to compile into
its suggestions template.
"""
config = Pool().get('elasticsearch.configuration')(1)
conn = config.get_es_connection(timeout=5)
results = []
search_obj = cls._quick_search_es(phrase, autocomplete=True)
# Return the top 5 results as a list of dictionaries
for product in conn.search(
search_obj,
doc_types=[config.make_type_name('product.product')],
size=5
):
display_name = product.name
if product.code:
display_name = '%s - %s' % (product.code, display_name)
results.append(
{
"id": product.id,
"type": product.type,
"display_name": display_name,
"url": cls(product.id).get_absolute_url(
_external=True
),
}
)
return results
示例2: _get_es_connection
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def _get_es_connection():
"""
Return a PYES connection
"""
warnings.warn(
"_get_es_connection will be deprecated in version 3.4\n"
"Pool().get('elasticsearch.configuration').get_es_connection() "
"replaces this method.",
DeprecationWarning
)
Configuration = Pool().get('elasticsearch.configuration')
return Configuration.get_es_connection()
示例3: update_index
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def update_index(cls, batch_size=100):
"""
Update the remote elastic search index from the backlog and
delete backlog entries once done.
To be scalable, this operation limits itself to handling the oldest
batch of records at a time. The batch_size can be optionally passed on
to this function call. This should be small enough for subsequent
transactions not to be blocked for a long time.
That depends on your specific implementation and index size.
"""
config = Pool().get('elasticsearch.configuration')(1)
conn = config.get_es_connection()
for item in cls.search_read(
[], order=[('id', 'DESC')], limit=batch_size,
fields_names=['record_model', 'record_id', 'id']):
Model = Pool().get(item['record_model'])
try:
record, = Model.search([('id', '=', item['record_id'])])
except ValueError:
# Record may have been deleted
try:
conn.delete(
config.index_name, # Index Name
config.make_type_name(Model.__name__), # Document Type
item['record_id']
)
except NotFoundException:
# This record was not there in elastic search too.
# Never mind!
pass
else:
if hasattr(record, 'elastic_search_json'):
# A model with the elastic_search_json method
data = record.elastic_search_json()
else:
# A model without elastic_search_json
data = cls._build_default_doc(record)
conn.index(
data,
config.index_name, # Index Name
config.make_type_name(record.__name__), # Document Type
record.id, # Record ID
)
finally:
# Delete the item since it has been sent to the index
cls.delete([cls(item['id'])])
示例4: auto_complete
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def auto_complete(cls, phrase):
"""
This is a downstream implementation which uses elasticsearch to return
results for a query.
"""
Product = Pool().get('product.product')
config = Pool().get('elasticsearch.configuration')(1)
if not config.get_es_connection(timeout=5):
# NO ES fallback to default search
return super(Website, cls).auto_complete(phrase)
return Product._es_autocomplete(phrase)
示例5: update_mapping
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def update_mapping(cls, document_types):
"""
Update the mapping on the server side
"""
config = Pool().get('elasticsearch.configuration')(1)
conn = config.get_es_connection()
for document_type in document_types:
conn.indices.put_mapping(
config.make_type_name(document_type.model.model), # Type
json.loads(document_type.mapping), # Mapping
[config.index_name], # Index
)
示例6: result_set
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def result_set(self):
"""
Generates the `~pyes.es.ResultSet` object after performing the search.
"""
config = Pool().get('elasticsearch.configuration')(1)
conn = config.get_es_connection(timeout=5)
return conn.search(
self.search_obj,
start=self.offset,
size=self.per_page,
doc_types=[config.make_type_name(self.model_name)]
)
示例7: all_items
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
def all_items(self):
"""
Returns all items.
"""
config = Pool().get('elasticsearch.configuration')(1)
conn = config.get_es_connection(timeout=5)
return self.model.browse(
map(
lambda p: p.id, conn.search(
self.search_obj,
doc_types=[
config.make_type_name(self.model_name)
]
)
)
)
示例8: quick_search
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import get_es_connection [as 别名]
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')
config = Pool().get('elasticsearch.configuration')(1)
if not config.get_es_connection(timeout=5):
# NO ES fallback to default search
return super(Website, cls).quick_search()
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
)