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 api_search(self, searchstring): if not searchstring.strip(): jsonresults = '[]' else: with Performance(_('processing whole search request')): searchresults = self.model.search(searchstring.strip()) with Performance(_('rendering search results as json')): jsonresults = [entry.to_dict() for entry in searchresults] return jsonresults
def api_search(self, value): if not value.strip(): jsonresults = '[]' else: with Performance('processing whole search request'): searchresults = self.model.search(value.strip()) with Performance('rendering search results as json'): jsonresults = self.jsonrenderer.render(searchresults) return jsonresults
def searchfor(self, value, maxresults=10): mode = 'normal' if value.startswith('!f '): mode = 'fileonly' value = value[3:] elif value.endswith(' !f'): mode = 'fileonly' value = value[:-3] elif value.startswith('!d '): mode = 'dironly' value = value[3:] elif value.endswith(' !d'): mode = 'dironly' value = value[:-3] reload(cherrymusicserver.tweak) file_search_limit = cherrymusicserver.tweak.SearchTweaks.normal_file_search_limit terms = SQLiteCache.searchterms(value) with Performance(_('searching for a maximum of %s files') % str(file_search_limit * len(terms))): if debug: log.d('searchterms') log.d(terms) results = [] maxFileIdsPerTerm = file_search_limit with Performance(_('file id fetching')): #unpack tuples fileids = [t[0] for t in self.fetchFileIds(terms, maxFileIdsPerTerm, mode)] if len(fileids) > file_search_limit: with Performance(_('sorting results by fileid occurrences')): resultfileids = {} for fileid in fileids: if fileid in resultfileids: resultfileids[fileid] += 1 else: resultfileids[fileid] = 1 # sort items by occurrences and only return maxresults fileids = sorted(resultfileids.items(), key=itemgetter(1), reverse=True) fileids = [t[0] for t in fileids] fileids = fileids[:min(len(fileids), file_search_limit)] if mode == 'normal': with Performance(_('querying fullpaths for %s fileIds') % len(fileids)): results += self.musicEntryFromFileIds(fileids) else: with Performance(_('querying fullpaths for %s fileIds, files only') % len(fileids)): results += self.musicEntryFromFileIds(fileids,mode=mode) if debug: log.d('resulting paths') log.d(results) return results
def searchfor(self, value, maxresults=10): mode = 'normal' if value.startswith('!f '): mode = 'fileonly' value = value[3:] elif value.endswith(' !f'): mode = 'fileonly' value = value[:-3] elif value.startswith('!d '): mode = 'dironly' value = value[3:] elif value.endswith(' !d'): mode = 'dironly' value = value[:-3] reload(cherrymusicserver.tweak) file_search_limit = cherrymusicserver.tweak.SearchTweaks.normal_file_search_limit terms = SQLiteCache.searchterms(value) with Performance( _('searching for a maximum of %s files') % str(file_search_limit * len(terms))): if debug: log.d('searchterms') log.d(terms) results = [] maxFileIdsPerTerm = file_search_limit with Performance(_('file id fetching')): fileids = self.fetchFileIds(terms, maxFileIdsPerTerm, mode) if len(fileids) > file_search_limit: with Performance(_('sorting results by fileid occurrences')): # sort items by occurrences and only return maxresults fileids = [ fid[0] for fid in Counter(fileids).most_common( file_search_limit) ] if mode == 'normal': with Performance( _('querying fullpaths for %s fileIds') % len(fileids)): results += self.musicEntryFromFileIds(fileids) else: with Performance( _('querying fullpaths for %s fileIds, files only') % len(fileids)): results += self.musicEntryFromFileIds(fileids, mode=mode) if debug: log.d('resulting paths') log.d(results) 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
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
def searchfor(self, value, maxresults=10): mode = 'normal' if value.startswith('!f '): mode = 'fileonly' value = value[3:] elif value.endswith(' !f'): mode = 'fileonly' value = value[:-3] elif value.startswith('!d '): mode = 'dironly' value = value[3:] elif value.endswith(' !d'): mode = 'dironly' value = value[:-3] terms = SQLiteCache.searchterms(value) with Performance('searching for a maximum of %s files' % str(NORMAL_FILE_SEARCH_LIMIT * len(terms))): if debug: log.d('searchterms') log.d(terms) results = [] maxFileIdsPerTerm = NORMAL_FILE_SEARCH_LIMIT with Performance('file id fetching'): #unpack tuples fileids = [ t[0] for t in self.fetchFileIds(terms, maxFileIdsPerTerm, mode) ] if len(fileids) > NORMAL_FILE_SEARCH_LIMIT: with Performance('sorting results by fileid occurrences'): resultfileids = {} for fileid in fileids: if fileid in resultfileids: resultfileids[fileid] += 1 else: resultfileids[fileid] = 1 # sort items by occurrences and only return maxresults fileids = sorted(resultfileids.items(), key=itemgetter(1), reverse=True) fileids = [t[0] for t in fileids] fileids = fileids[:min(len(fileids ), NORMAL_FILE_SEARCH_LIMIT)] if mode == 'normal': with Performance('querying fullpaths for %s fileIds' % len(fileids)): results += self.musicEntryFromFileIds(fileids) else: with Performance( 'querying fullpaths for %s fileIds, files only' % len(fileids)): results += self.musicEntryFromFileIds(fileids, mode=mode) if debug: log.d('resulting paths') log.d(results) return results