- searcher = self.index.searcher()
- # XXX is this kosher? docs say search() takes a weighting arg, but it
- # certainly does not
- searcher.weighting = LanguageWeighting()
- results = searcher.search(query,
- limit=self.INTERMEDIATE_LOOKUP_RESULTS)
+ # Limits; result limits are constants, and intermediate results (before
+ # duplicate items are stripped out) are capped at the result limit
+ # times another constant.
+ # Fuzzy are capped at 10, beyond which something is probably very
+ # wrong. Exact matches -- that is, wildcards and ids -- are far less
+ # constrained.
+ # Also, exact matches are sorted by name, since weight doesn't matter.
+ sort_by = dict()
+ if exact_only:
+ max_results = self.MAX_EXACT_RESULTS
+ sort_by['sortedby'] = (u'table', u'name')
+ else:
+ max_results = self.MAX_FUZZY_RESULTS
+
+ searcher = self.index.searcher(weighting=LanguageWeighting())
+ results = searcher.search(
+ query,
+ limit=int(max_results * self.INTERMEDIATE_FACTOR),
+ **sort_by
+ )