<commit_before>import logging

from molly.apps.search.providers import BaseSearchProvider

from molly.conf import applications

logger = logging.getLogger('molly.providers.apps.search.application_search')

class ApplicationSearchProvider(BaseSearchProvider):
    def __init__(self, application_names=None):
        self.application_names = application_names
        self.applications = None
        
    def perform_search(self, request, query, application=None):
        if self.applications == None:
            self.find_applications()
        
        if application:
            if not application in self.applications:
                return []
            apps = [self.applications[application]]
        else:
            apps = self.applications.values()

        results = []
        for app in apps:
            try:
                results += app.perform_search(request, query, application)
            except Exception, e:
                logger.exception("Application search provider raised exception: %r", e)
                pass
        
        print apps
        return results
        
    def find_applications(self):
        self.applications = {}
        for app_name in applications:
            application = applications[app_name]
            
            if self.application_names and not application in self.application_names:
                continue
            try:
                search_module_name = '%s.search' % application.name
                _temp = __import__(search_module_name,
                                   globals(), locals(),
                                   ['SearchProvider'], -1)
                if not hasattr(_temp, 'SearchProvider'):
                    raise ImportError
            except ImportError:
                continue
            else:
                search_provider = _temp.SearchProvider

            self.applications[application.slug] = search_provider
            
        <commit_msg>Update ApplicationSearchProvider to reflect conf.settings.Application changes.<commit_after>import logging

from molly.apps.search.providers import BaseSearchProvider

from molly.conf import applications

logger = logging.getLogger('molly.providers.apps.search.application_search')

class ApplicationSearchProvider(BaseSearchProvider):
    def __init__(self, local_names=None):
        self.local_names = local_names
        self.applications = None
        
    def perform_search(self, request, query, application=None):
        if self.applications == None:
            self.find_applications()
        
        if application:
            if not application in self.applications:
                return []
            apps = [self.applications[application]]
        else:
            apps = self.applications.values()

        results = []
        for app in apps:
            try:
                results += app.perform_search(request, query, application)
            except Exception, e:
                logger.exception("Application search provider raised exception: %r", e)
                pass
        
        print apps
        return results
        
    def find_applications(self):
        self.applications = {}
        for local_name in applications:
            application = applications[local_name]
            
            if self.local_names and not application in self.local_names:
                continue
            try:
                search_module_name = '%s.search' % application.application_name
                _temp = __import__(search_module_name,
                                   globals(), locals(),
                                   ['SearchProvider'], -1)
                if not hasattr(_temp, 'SearchProvider'):
                    raise ImportError
            except ImportError:
                continue
            else:
                search_provider = _temp.SearchProvider

            self.applications[application.local_name] = search_provider
            
        
{'fraction_non_alphanumeric': 0.06871381827334508, 'fraction_numerical': 0.0005033979360684622, 'mean_word_length': 1.7237834132967786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5632156', 'n_tokens_mistral': 914, 'n_tokens_neox': 884, 'n_words': 223}