def search(self, term): reload(cherry.tweak) tweaks = cherry.tweak.CherryModelTweaks user = cherrypy.session.get('username', None) if user: log.d(_("%(user)s searched for '%(term)s'"), { 'user': user, 'term': term }) max_search_results = cherry.config['search.maxresults'] results = self.cache.searchfor(term, maxresults=max_search_results) with Performance(_('sorting DB results using ResultOrder')) as perf: debug = tweaks.result_order_debug order_function = resultorder.ResultOrder(term, debug=debug) results = sorted(results, key=order_function, reverse=True) results = results[:min(len(results), max_search_results)] if debug: n = tweaks.result_order_debug_files for sortedResults in results[:n]: perf.log(sortedResults.debugOutputSort) for sortedResults in results: sortedResults.debugOutputSort = None # free ram with Performance(_('checking and classifying results:')): results = list(filter(CherryModel.isValidMediaEntry, results)) if cherry.config['media.show_subfolder_count']: for result in results: result.count_subfolders_and_files() return results
def search(self, term): reload(cherry.tweak) tweaks = cherry.tweak.CherryModelTweaks user = cherrypy.session.get('username', None) if user: log.d(user + ' searched for "' + term + '"') max_search_results = cherry.config['search.maxresults'] results = self.cache.searchfor(term, maxresults=max_search_results) with Performance('sorting DB results using ResultOrder'): debug = tweaks.result_order_debug order_function = resultorder.ResultOrder(term, debug=debug) results = sorted(results, key=order_function, reverse=True) results = results[:min(len(results), max_search_results)] if debug: n = tweaks.result_order_debug_files for sortedResults in results[:n]: Performance.log(sortedResults.debugOutputSort) for sortedResults in results: sortedResults.debugOutputSort = None # free ram with Performance('checking and classifying results:'): results = list(filter(isValidMediaFile, results)) return results