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
            
        

@@ -260,27 +260,21 @@
 _(self, 
-application
+local
 _names=N
@@ -296,39 +296,27 @@
 elf.
-application_names = application
+local_names = local
 _nam
@@ -1140,19 +1140,21 @@
     for 
-app
+local
 _name in
@@ -1207,19 +1207,21 @@
 cations%5B
-app
+local
 _name%5D%0A 
@@ -1248,35 +1248,29 @@
     if self.
-application
+local
 _names and n
@@ -1292,27 +1292,21 @@
 in self.
-application
+local
 _names:%0A
@@ -1410,16 +1410,28 @@
 ication.
+application_
 name%0A   
@@ -1869,12 +1869,18 @@
 ion.
-slug
+local_name
 %5D = 

Update ApplicationSearchProvider to reflect conf.settings.Application changes.