本文整理汇总了Python中google.appengine.api.search.QueryOptions方法的典型用法代码示例。如果您正苦于以下问题:Python search.QueryOptions方法的具体用法?Python search.QueryOptions怎么用?Python search.QueryOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.search
的用法示例。
在下文中一共展示了search.QueryOptions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def get(self):
index_name = self.request.get('index')
if not index_name:
self.redirect('/search')
return
start = self.request.get_range('start', min_value=0, default=0)
query = self.request.get('query')
namespace = self.request.get('namespace')
index = search.Index(name=index_name, namespace=namespace)
resp = index.search(query=search.Query(
query_string=query,
options=search.QueryOptions(offset=start,
limit=self._MAX_RESULTS_PER_PAGE)))
has_more = resp.number_found > start + self._MAX_RESULTS_PER_PAGE
values = {
'namespace': namespace,
'index': index_name,
'start': start,
'query': query,
'values': self._process_search_response(resp),
}
self._handle_paging(start, has_more, values)
self.response.write(self.render('search_index.html', values))
示例2: query_offset
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def query_offset(index, query_string):
offset = 0
while True:
# Build the query using the current offset.
options = search.QueryOptions(offset=offset)
query = search.Query(query_string=query_string, options=options)
# Get the results
results = index.search(query)
number_retrieved = len(results.results)
if number_retrieved == 0:
break
# Add the number of documents found to the offset, so that the next
# iteration will grab the next page of documents.
offset += number_retrieved
# Process the matched documents
for document in results:
print(document)
示例3: search_query
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def search_query(self, query_string, page=0):
# Create sort options to sort on price and brand.
sort_ts = search.SortExpression(
expression='ts',
direction=search.SortExpression.DESCENDING,
default_value=0)
sort_options = search.SortOptions(expressions=[sort_ts])
# Create query options using the sort options and expressions created
# above.
query_options = search.QueryOptions(
limit=self.MSG_PER_PAGE_NUM,
offset=page * self.MSG_PER_PAGE_NUM,
returned_fields=['msg_key'],
sort_options=sort_options)
# Build the Query and run the search
try:
query = search.Query(query_string=query_string, options=query_options)
except search.QueryError:
return []
results = self.index.search(query)
return results
示例4: get
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def get(self):
super(SearchIndexHandler, self).get()
index_name = self.request.get('index')
if not index_name:
self.redirect('/search')
return
start = self.request.get_range('start', min_value=0, default=0)
query = self.request.get('query')
namespace = self.request.get('namespace')
index = search.Index(name=index_name, namespace=namespace)
resp = index.search(query=search.Query(
query_string=query,
options=search.QueryOptions(offset=start,
limit=self._MAX_RESULTS_PER_PAGE)))
has_more = resp.number_found > start + self._MAX_RESULTS_PER_PAGE
values = {
'namespace': namespace,
'index': index_name,
'start': start,
'query': query,
'values': self._process_search_response(resp),
}
self._handle_paging(start, has_more, values)
self.response.write(self.render('search_index.html', values))
示例5: search
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def search(
cls, query_string='', query_limit=20, cursor=None, sort_options=None,
returned_fields=None):
"""Searches for documents that match a given query string.
Args:
query_string: str, the query to match against documents in the index
query_limit: int, the limit on number of documents to return in results.
cursor: search.Cursor, a cursor describing where to get the next set of
results, or to provide next cursors in SearchResults.
sort_options: search.SortOptions, an object specifying a multi-dimensional
sort over search results.
returned_fields: List[str], an iterable of names of fields to return in
search results.
Returns:
A SearchResults object containing a list of documents matched by the
query.
"""
index = cls.get_index()
try:
query = search.Query(
query_string=cls.format_query(query_string),
options=search.QueryOptions(
cursor=cursor, limit=query_limit, sort_options=sort_options,
returned_fields=returned_fields),
)
except search.QueryError:
return search.SearchResults(number_found=0)
return index.search(query)
示例6: find
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def find(query, count=10):
sort_opts = search.SortOptions(expressions=[search.SortExpression(
expression="date", direction=search.SortExpression.ASCENDING)])
query_options = search.QueryOptions(limit=count, sort_options=sort_opts)
query_obj = search.Query(query_string=query, options=query_options)
results = index.search(query=query_obj)
keys = []
for result in results:
keys.append(result.doc_id)
return keys
示例7: query_options
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def query_options():
index = search.Index('products')
query_string = "product: piano AND price < 5000"
# Create sort options to sort on price and brand.
sort_price = search.SortExpression(
expression='price',
direction=search.SortExpression.DESCENDING,
default_value=0)
sort_brand = search.SortExpression(
expression='brand',
direction=search.SortExpression.DESCENDING,
default_value="")
sort_options = search.SortOptions(expressions=[sort_price, sort_brand])
# Create field expressions to add new fields to the scored documents.
price_per_note_expression = search.FieldExpression(
name='price_per_note', expression='price/88')
ivory_expression = search.FieldExpression(
name='ivory', expression='snippet("ivory", summary, 120)')
# Create query options using the sort options and expressions created
# above.
query_options = search.QueryOptions(
limit=25,
returned_fields=['model', 'price', 'description'],
returned_expressions=[price_per_note_expression, ivory_expression],
sort_options=sort_options)
# Build the Query and run the search
query = search.Query(query_string=query_string, options=query_options)
results = index.search(query)
for scored_document in results:
print(scored_document)
示例8: query_cursor
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def query_cursor(index, query_string):
cursor = search.Cursor()
while cursor:
# Build the query using the cursor.
options = search.QueryOptions(cursor=cursor)
query = search.Query(query_string=query_string, options=options)
# Get the results and the next cursor
results = index.search(query)
cursor = results.cursor
for document in results:
print(document)
示例9: query_per_document_cursor
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def query_per_document_cursor(index, query_string):
cursor = search.Cursor(per_result=True)
# Build the query using the cursor.
options = search.QueryOptions(cursor=cursor)
query = search.Query(query_string=query_string, options=options)
# Get the results.
results = index.search(query)
document_cursor = None
for document in results:
# discover some document of interest and grab its cursor, for this
# sample we'll just use the first document.
document_cursor = document.cursor
break
# Start the next search from the document of interest.
if document_cursor is None:
return
options = search.QueryOptions(cursor=document_cursor)
query = search.Query(query_string=query_string, options=options)
results = index.search(query)
for document in results:
print(document)
示例10: employees_matching_prefix
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def employees_matching_prefix(prefix):
"""Returns a list of (full name, username) tuples for users that match the given prefix."""
if not prefix:
return []
user_tuples = set()
search_query = search.Query(
query_string=prefix,
options=search.QueryOptions(
limit=15))
results = search.Index(name=INDEX_NAME).search(search_query)
for r in results:
username, full_name = None, None
for f in r.fields:
if f.name == 'full_name':
full_name = f.value
elif f.name == 'username':
username = f.value
else:
continue
if username is not None and full_name is not None:
photo_url = Employee.query(Employee.username == username).get().get_photo_url()
user_tuples.add((full_name, username, photo_url))
user_tuples = list(user_tuples)
user_tuples.sort()
return user_tuples
示例11: get
# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import QueryOptions [as 别名]
def get(self):
"""Displays documents in a FTS index."""
start = self.request.get_range('start', min_value=0, default=0)
query = self.request.get('query')
namespace = self.request.get('namespace')
limit = self.request.get_range('num', min_value=1, max_value=100,
default=10)
index_name = self.request.get('index') or 'index'
index = search.Index(name=index_name, namespace=namespace)
resp = index.search(query=search.Query(
query_string=query,
options=search.QueryOptions(offset=start, limit=limit)))
has_more = resp.number_found > start + limit
current_page = start / limit + 1
values = {
'request': self.request,
'namespace': namespace,
'index': index_name,
'query': query,
'current_page': current_page,
'next_start': -1,
'prev_start': -1,
'start_base_url': self.filter_url([
'query', 'index', 'num', 'namespace']),
'next': urllib.quote(ustr(self.request.uri)),
'values': self._ProcessSearchResponse(resp),
'prev': self.request.get(
'next',
default_value=self.base_path() + SearchIndexesListHandler.PATH)}
if current_page > 1:
values['prev_start'] = int((current_page - 2) * limit)
values['paging'] = True
if has_more:
values['next_start'] = int(current_page * limit)
values['paging'] = True
self.generate('search_index.html', values)