Thomas Waldmann avatar Thomas Waldmann committed 4be30d1

search: do not call key_terms() to find out term suggestions, it is slooooow

Comments (0)

Files changed (1)

MoinMoin/apps/frontend/views.py

             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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.