source: fulltextsearchplugin/trunk/trac_fts.patch

Last change on this file was 11692, checked in by Alex Willmer, 11 years ago

FullTextSearchPlugin: Include Trac patch

File size: 2.9 KB
RevLine 
[11692]1Index: trac/search/web_ui.py
2===================================================================
3--- trac/search/web_ui.py   (revision 11072)
4+++ trac/search/web_ui.py   (working copy)
5@@ -41,8 +41,20 @@
6     implements(INavigationContributor, IPermissionRequestor, IRequestHandler,
7                ITemplateProvider, IWikiSyntaxProvider)
8 
9-    search_sources = ExtensionPoint(ISearchSource)
10+    _search_sources = ExtensionPoint(ISearchSource)
11     
12+    @property
13+    def search_sources(self):
14+        return [source for source in self._search_sources
15+                if source.__class__.__name__ not in self.disabled_sources]
16+
17+    disabled_sources = ListOption('search', 'disabled_sources',
18+                                  [],
19+        doc="""Components that will be skipped as search sources. Used by
20+        FullTextSearchPlugin to override sources it has implemented.
21+
22+        Logica addition.""")
23+
24     RESULTS_PER_PAGE = 10
25 
26     min_query_length = IntOption('search', 'min_query_length', 3,
27@@ -60,6 +72,23 @@
28                be manually enabled by the user on the search page.
29                (since 0.12)""")
30 
31+    # Public methods
32+
33+    def get_available_filters(self, req):
34+        """Return a list of filters that are available.
35+       
36+        Each filter is a `(name, label, default)` tuple, where `name` is
37+        the internal name, `label` is a human-readable name for display and
38+        `default` is a boolean for determining whether this filter is
39+        searchable by default.
40+        """
41+        if 'SEARCH_VIEW' in req.perm:
42+            return [(f[0], f[1], (len(f) < 3 or len(f) > 2 and f[2]))
43+                    for source in self.search_sources
44+                    for f in (source.get_search_filters(req) or [])]
45+        else:
46+            return []
47+
48     # INavigationContributor methods
49 
50     def get_active_navigation_item(self, req):
51@@ -88,11 +117,7 @@
52                     'application/opensearchdescription+xml')
53 
54         query = req.args.get('q')
55-        available_filters = []
56-        for source in self.search_sources:
57-            available_filters.extend(source.get_search_filters(req) or [])
58-        available_filters.sort(key=lambda f: f[1].lower())
59-       
60+        available_filters = self.get_available_filters(req)
61         filters = self._get_selected_filters(req, available_filters)
62         data = self._prepare_data(req, query, available_filters, filters)
63         if query:
64@@ -144,8 +169,7 @@
65         filters = [f[0] for f in available_filters if f[0] in req.args]
66         if not filters:
67             filters = [f[0] for f in available_filters
68-                       if f[0] not in self.default_disabled_filters and
69-                       (len(f) < 3 or len(f) > 2 and f[2])]
70+                       if f[0] not in self.default_disabled_filters and f[2]]
71         return filters
72         
73     def _prepare_data(self, req, query, available_filters, filters):
Note: See TracBrowser for help on using the repository browser.