Hi,

We have a lot of wiki pages that we do not want to be part of a search
result (basically, we store team minutes in the wiki, so there are a
lot of "minutes" pages that refer to useful terms but do not carry
much information outside the minutes' scope)

I've added an exclusion list for the search feature from the wiki page.

I do not know whether it can be useful for some other trac users, I
don't think it is worth logging a ticket for such a local enhancement.
However, here is the patch (against trunk [2979]) for reference
(attached).

To use it, simply define a new [wiki] section with a search_exclude
option in your trac.ini file:

[wiki]
search_exclude = team*minutes* teamweek*

(where * is a joker character)

HTH,
Manu
--- vendor/trac/current/trac/wiki/web_ui.py	2006-03-09 20:41:49.117429400 +0100
+++ trunk/trac/trac/wiki/web_ui.py	2006-03-09 20:57:31.826587700 +0100
@@ -390,13 +390,21 @@
     def get_search_results(self, req, terms, filters):
         if not 'wiki' in filters:
             return
+        search_exclude = self.env.config.get('wiki', 'search_exclude')
+        exclude_list = search_exclude.replace('*', '%%').split(' ')
         db = self.env.get_db_cnx()
+        if len(exclude_list) > 0:
+            like = db.like()
+            exclude_sql = ["name NOT %s '%s' " % (like, item) for item in exclude_list]
+            exclude = " WHERE %s" % "AND ".join(exclude_sql)
+        else:
+            exclude = " "
         sql_query, args = search_to_sql(db, ['w1.name', 'w1.author', 'w1.text'], terms)
         cursor = db.cursor()
         cursor.execute("SELECT w1.name,w1.time,w1.author,w1.text "
                        "FROM wiki w1,"
                        "(SELECT name,max(version) AS ver "
-                       "FROM wiki GROUP BY name) w2 "
+                       "FROM wiki" + exclude + "GROUP BY name) w2 "
                        "WHERE w1.version = w2.ver AND w1.name = w2.name "
                        "AND " + sql_query, args)
 
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac

Reply via email to