changeset 830:4be30d1fdb5d

search: do not call key_terms() to find out term suggestions, it is slooooow
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 02 Sep 2011 16:34:51 +0200
parents 1cdd8d4eaed4
children b277658ba85c
files MoinMoin/apps/frontend/views.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Fri Sep 02 16:06:50 2011 +0200
+++ b/MoinMoin/apps/frontend/views.py	Fri Sep 02 16:34:51 2011 +0200
@@ -159,11 +159,22 @@
             flaskg.clock.start('search')
             results = searcher.search(q, limit=100)
             flaskg.clock.stop('search')
+            # XXX if found that calling key_terms like you see below is 1000..10000x
+            # slower than the search itself, so we better don't do that right now.
+            key_terms_is_fast = False
+            if key_terms_is_fast:
+                flaskg.clock.start('search suggestions')
+                name_suggestions = u', '.join([word for word, score in results.key_terms(NAME, docs=20, numterms=10)])
+                content_suggestions = u', '.join([word for word, score in results.key_terms(CONTENT, docs=20, numterms=10)])
+                flaskg.clock.stop('search suggestions')
+            else:
+                name_suggestions = u''
+                content_suggestions = u''
             flaskg.clock.start('search render')
             html = render_template('search.html',
                                    results=results,
-                                   name_suggestions=u', '.join([word for word, score in results.key_terms(NAME, docs=20, numterms=10)]),
-                                   content_suggestions=u', '.join([word for word, score in results.key_terms(CONTENT, docs=20, numterms=10)]),
+                                   name_suggestions=name_suggestions,
+                                   content_suggestions=content_suggestions,
                                    query=query,
                                    medium_search_form=search_form,
                                    item_name='+search', # XXX