Skip to content

Commit 2a431ea

Browse files
author
Joe Kohlmann
committed
Added a new config option to control whether or not results aggregation is aborted if there are more than 8000 results. This is useful when using a debug configuration to generate a search results cache offline.
1 parent dc3453b commit 2a431ea

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

flask/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class Config(object):
2222
CACHE_ROOT,
2323
"queries.json"
2424
)
25+
LIMIT_QUERIES = True
2526

2627

2728
class DevelopmentConfig(Config):
2829
DEBUG = True
30+
LIMIT_QUERIES = False

flask/nyt_api/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ def __init__(self, **kwargs):
107107
else:
108108
self.debug = False
109109

110+
# Limit Queries
111+
if "limit_queries" in kwargs:
112+
self.limit_queries = kwargs["limit_queries"]
113+
else:
114+
# Default to True since retrieving article data for more than 8000 results is prohibitive
115+
self.limit_queries = True
116+
110117
# Replace existing cache files
111118
if "replace_existing_cache_files" in kwargs:
112119
self.replace = kwargs["replace_existing_cache_files"]
@@ -143,7 +150,7 @@ def search(self, **query_params):
143150
if self.debug:
144151
print "No hits for query '%s'" % query_params
145152
return None
146-
elif ir_stats["hits"] > self.query_max_hits:
153+
elif self.limit_queries and ir_stats["hits"] > self.query_max_hits:
147154
if self.debug:
148155
print "More than %d hits (%d hits, to be exact) for query '%s'" % (self.query_max_hits, ir_stats["hits"], query_params)
149156
return None

flask/util/search.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
),
4141
search_api_key=Config.SEARCH_API_KEY,
4242
debug=Config.DEBUG,
43+
limit_queries=Config.LIMIT_QUERIES,
4344
replace=True
4445
)
4546

0 commit comments

Comments
 (0)