From 350b22ee0eb4ff47c6a0339927e9009aa6845ba3 Mon Sep 17 00:00:00 2001 From: "amyu@google.com" Date: Wed, 9 May 2012 00:25:02 +0000 Subject: [PATCH] remove use of 1.6.4-compatible 'wrapper' git-svn-id: http://google-app-engine-samples.googlecode.com/svn/trunk@157 99225164-8649-0410-878b-2ba91e509939 --- search/python/search_demo.py | 12 ++------ search/python/sortoptions.py | 69 -------------------------------------------- 2 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 search/python/sortoptions.py diff --git a/search/python/search_demo.py b/search/python/search_demo.py index 8cefb59..0edd8b9 100644 --- a/search/python/search_demo.py +++ b/search/python/search_demo.py @@ -18,10 +18,6 @@ from google.appengine.ext import webapp from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app -# contains a function to allow proper construction of sort options in both -# release 1.6.4 and 1.6.5+. See code below. -import sortoptions - _INDEX_NAME = 'greeting' @@ -43,11 +39,9 @@ class MainPage(webapp.RequestHandler): expr_list = [search.SortExpression( expression='author', default_value='', direction=search.SortExpression.DESCENDING)] - # construct the sort options value using the get_sort_options() wrapper - # function, which will work correctly in both release 1.6.4 and - # release 1.6.5+. - sort_opts = sortoptions.get_sort_options( - expr_list, match_scorer=None) + # construct the sort options + sort_opts = search.SortOptions( + expressions=expr_list) query_options = search.QueryOptions( limit=3, sort_options=sort_opts) diff --git a/search/python/sortoptions.py b/search/python/sortoptions.py deleted file mode 100644 index 71af03e..0000000 --- a/search/python/sortoptions.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2012 Google Inc. All Rights Reserved. - - -import logging - -from google.appengine.api import search - - -def get_sort_options(expressions=None, match_scorer=None, limit=1000): - """Constructs sort options for 1.6.4 and 1.6.5 API differences. - - An example of usage (NOTE: Do NOT set limit on SortExpression or MatchScorer): - - expr_list = [ - search.SortExpression(expression='author', default_value='', - direction=search.SortExpression.DESCENDING)] - sort_opts = get_sort_options(expression=expr_list, limit=sort_limit) - - The returned value is used in constructing the query options: - - options=search.QueryOptions(limit=doc_limit, sort_options=sort_opts) - - Another example illustrating sorting on an expression based on a - MatchScorer score: - - expr_list = [ - search.SortExpression(expression='_score + 0.001 * rating', - default_value='', - direction=search.SortExpression.DESCENDING)] - sort_opts = get_sort_options(expression=expr_list, - match_scorer=search.MatchScorer(), - limit=sort_limit) - - - Args: - expression: a list of search.SortExpression. Do not set limit parameter on - SortExpression - match_scorer: a search.MatchScorer or search.RescoringMatchScorer. Do not - set limit parameter on either scorer - limit: the scoring limit - - Returns: the sort options value, either list of SortOption (1.6.4) or - SortOptions (1.6.5), to set the sort_options field in the QueryOptions object. - """ - try: - # using 1.6.5 or greater - if search.SortOptions: - logging.info("search.SortOptions is defined.") - return search.SortOptions( - expressions=expressions, match_scorer=match_scorer, limit=limit) - - # SortOptions not available, so using 1.6.4 - except AttributeError: - logging.info("search.SortOptions is not defined.") - expr_list = [] - # copy the sort expressions including the limit info - if expressions: - expr_list = [ - search.SortExpression( - expression=e.expression, direction=e.direction, - default_value=e.default_value, limit=limit) - for e in expressions] - # add the match scorer, if defined, to the expressions list. - if isinstance(match_scorer, search.MatchScorer): - expr_list.append(match_scorer.__class__(limit=limit)) - logging.debug("sort expressions: %s", expr_list) - return expr_list -- 2.11.4.GIT