Many small cleanups and simplifications.
_indexedSearch(): Simplify logic that called _apply_index() for each index in the catalog. The if statement under the comment "Optimization" had identical code on either branch. Perhaps the odd indentation made this confusing. Regardless, remove the conditional. Change computation of normalized scores to multiply first, then divide. Use literal 100. to make sure mult and div are floating point ops. searchResults(): Simplify logic at beginning of searchResults(). The first two conditionals depended on kw, so organize the logic to make that clearer. Write helper method to find "sort-on" and "sort-index" instead of duplicating code in searchResults(). For case were results are sorted, simplify construction of the final LazyCat and make it more efficient to boot. Instead of use a list comprehension and a reduce + lambda to construct list and length of contained lists, do it with one explicit for loop that constructs both values. Note: I did detailed timing stats on three ways to compute the length of a sequence of sequences. reduce + lambda was the slowest. For short lists, an explicit for loop is fastest. For long lists, reduce(operater.add, map(len, list)) is fastest. The explicit for loop is big win here, because we've got to walk over the elements anyway to undo the Schwarzian transform. Sundry: Use getattr() with default value of None in preference to hasattr() followed by getattr(). This gets the same result with half the work. Changes for consistent and frequent use of whitespace. Use types.StringType and isinstance() to test for strings.
Showing
This diff is collapsed.
Please register or sign in to comment