Commits

James Taylor committed 9a9d3fb

Tool search working

  • Participants
  • Parent commits 913228e

Comments (0)

Files changed (4)

-repoze.profile
-workflow-speed
+tool-search

tool-search-backend

-diff --git a/eggs.ini b/eggs.ini
---- a/eggs.ini
-+++ b/eggs.ini
-@@ -53,6 +53,7 @@
- wsgiref = 0.1.2
- Babel = 0.9.4
- wchartype = 0.1
-+Whoosh = 0.3.18
- boto = 1.8d
- 
- ; extra version information
-@@ -106,4 +107,5 @@
- wsgiref = http://pypi.python.org/packages/source/w/wsgiref/wsgiref-0.1.2.zip
- Babel = http://ftp.edgewall.com/pub/babel/Babel-0.9.4.zip
- wchartype = http://ginstrom.com/code/wchartype-0.1.zip
-+Whoosh = http://pypi.python.org/packages/source/W/Whoosh/Whoosh-0.3.18.tar.gz
- boto = http://boto.googlecode.com/files/boto-1.8d.tar.gz
-diff --git a/lib/galaxy/app.py b/lib/galaxy/app.py
---- a/lib/galaxy/app.py
-+++ b/lib/galaxy/app.py
-@@ -1,6 +1,7 @@
- import sys, os, atexit
- 
- from galaxy import config, jobs, util, tools, web, cloud
-+import galaxy.tools.search
- ## from galaxy.tracks import store
- from galaxy.web import security
- import galaxy.model
-@@ -35,6 +36,8 @@
-         self.security = security.SecurityHelper( id_secret=self.config.id_secret )
-         # Initialize the tools
-         self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path, self )
-+        # Search support for tools
-+        self.toolbox_search = galaxy.tools.search.ToolBoxSearch( self.toolbox )
-         # Load datatype converters
-         self.datatypes_registry.load_datatype_converters( self.toolbox )
-         #load external metadata tool
-diff --git a/lib/galaxy/tools/search/__init__.py b/lib/galaxy/tools/search/__init__.py
-new file mode 100644
---- /dev/null
-+++ b/lib/galaxy/tools/search/__init__.py
-@@ -0,0 +1,36 @@
-+from galaxy.eggs import require
-+require( "Whoosh" )
-+
-+from whoosh.filedb.filestore import RamStorage
-+from whoosh.fields import Schema, STORED, ID, KEYWORD, TEXT
-+from whoosh.index import Index
-+from whoosh.qparser import QueryParser
-+
-+schema = Schema( id = STORED, title = TEXT, help = TEXT )
-+
-+class ToolBoxSearch( object ):
-+    """
-+    Support searching tools in a toolbox. This implementation uses
-+    the "whoosh" search library.
-+    """
-+    
-+    def __init__( self, toolbox ):
-+        """
-+        Create a searcher for `toolbox`. 
-+        """
-+        self.toolbox = toolbox
-+        self.build_index()
-+        
-+    def build_index( self ):
-+        self.storage = RamStorage()
-+        self.index = self.storage.create_index( schema )
-+        writer = self.index.writer()
-+        for id, tool in self.toolbox.tools_by_id.iteritems():
-+            writer.add_document( id=id, title=unicode(tool.name), help=unicode(tool.help) )
-+        writer.commit()
-+        
-+    def search( self, query, return_attribute='id' ):
-+        searcher = self.index.searcher()
-+        parser = QueryParser( "help", schema = schema )
-+        results = searcher.search( parser.parse( query ) )
-+        return [ result[ return_attribute ] for result in results ]
-\ No newline at end of file
-diff --git a/lib/galaxy/web/controllers/root.py b/lib/galaxy/web/controllers/root.py
---- a/lib/galaxy/web/controllers/root.py
-+++ b/lib/galaxy/web/controllers/root.py
-@@ -32,6 +32,10 @@
-         else:
-             return trans.fill_template('/root/tool_menu.mako', toolbox=self.get_toolbox() )
- 
-+    @web.json
-+    def tool_search( self, trans, query ):
-+        return trans.app.toolbox_search.search( query )
-+
-     @web.expose
-     def tool_help( self, trans, id ):
-         """Return help page for tool identified by 'id' if available"""
-diff --git a/templates/root/tool_menu.mako b/templates/root/tool_menu.mako
---- a/templates/root/tool_menu.mako
-+++ b/templates/root/tool_menu.mako
-@@ -85,6 +85,12 @@
- 
-     <body class="toolMenuPage">
-         <div class="toolMenu">
-+            <div id="tool-search">
-+                <form action="tool_search">
-+                    <input type="text" name="query">
-+                </form>
-+            </div>
-+            
-             <div class="toolSectionList">
-                 
-                 %for key, val in toolbox.tool_panel.items():

tool-search-ui

-diff --git a/templates/root/index.mako b/templates/root/index.mako
---- a/templates/root/index.mako
-+++ b/templates/root/index.mako
-@@ -66,10 +66,60 @@
-     </script>
- %endif
- </%def>
-+    
-+<%def name="late_javascripts()">
-+    ${parent.late_javascripts()}
-+    <script type="text/javascript">
-+        $(function() {
-+            $("#tools-search").each( function() {
-+                var tb = $(this).find( "input" );
-+                var cancel = $(this).find( ".cancel" );
-+                tb.hide();
-+                cancel.hide();
-+                $(this).find( ".activate" ).click( function() {
-+                    tb.show();
-+                    cancel.show();
-+                })
-+                $(this).find(".cancel").click( function() {
-+                    console.log( "cancel", tb );
-+                    tb.value = "";
-+                })
-+            })
-+        })
-+    </script>
-+</%def>
- 
- <%def name="left_panel()">
-+    <style type="text/css">
-+        .right {
-+            float: right;
-+            border: solid red 1px;
-+        }
-+        .positioned {
-+            position: relative;
-+        }
-+        #tools-search {
-+            border: solid grey 1px;
-+            margin: 0;
-+            -webkit-border-radius: 0.6em;
-+            padding: 0px 16px;
-+        }
-+        #tools-search input {
-+            margin: 0; padding: 0;
-+            border: solid white 1px;
-+        }
-+    </style>
-+
-     <div class="unified-panel-header" unselectable="on">
--        <div class='unified-panel-header-inner'>${n_('Tools')}</div>
-+        <div class='unified-panel-header-inner'>
-+            <div id="tools-search" class="right positioned">
-+                <input type="text"/>
-+                <img class="activate" src="" width="16" height="16" style="background: red; position: absolute; left: 0; top: 0;"/>
-+                <img class="cancel" src="" width="16" height="16" style="background: blue; position: absolute; right: 0; top: 0;"/>
-+            </div>
-+            
-+            ${n_('Tools')}
-+        </div>
-     </div>
-     <div class="unified-panel-body" style="overflow: hidden;">
-         <iframe name="galaxy_tools" src="${h.url_for( controller='root', action='tool_menu' )}" frameborder="0" style="position: absolute; margin: 0; border: 0 none; height: 100%; width: 100%;"> </iframe>