~loggerhead-team/loggerhead/trunk-rich

185 by Martin Albisetti
* Clarify License and add copyright to all file headers (John Arbash Meinel)
1
# Copyright (C) 2008  Canonical Ltd.
2
#                     (Authored by Martin Albisetti <argentina@gmail.com>)
128.10.5 by Martin Albisetti
* Added logic to suggest search terms while typing
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
#
18
128.10.11 by Martin Albisetti
Merge from trunk
19
from loggerhead.controllers import TemplatedBranchView
128.10.5 by Martin Albisetti
* Added logic to suggest search terms while typing
20
from loggerhead import search
21
22
128.10.11 by Martin Albisetti
Merge from trunk
23
class SearchUI(TemplatedBranchView):
128.10.5 by Martin Albisetti
* Added logic to suggest search terms while typing
24
    """
201.2.15 by Michael Hudson
fix pyflakes warnings, including nameerror in annotate_ui.py
25
128.10.5 by Martin Albisetti
* Added logic to suggest search terms while typing
26
    Class to output progressive search result terms.
27
    """
128.10.11 by Martin Albisetti
Merge from trunk
28
29
    template_path = 'loggerhead.templates.search'
30
249.1.1 by Robert Collins
Faster search logic - less double checking etc etc, seems to work.
31
    def get_values(self, path, kwargs, response):
128.10.5 by Martin Albisetti
* Added logic to suggest search terms while typing
32
        """
33
        Default method called from the search box as /search URL
34
35
        Returns a list of suggested search terms parsed through the
36
        templating engine.
37
        """
38
        terms = []
39
        query = kwargs['query']
40
        if len(query) > 0:
249.1.1 by Robert Collins
Faster search logic - less double checking etc etc, seems to work.
41
            terms = search.search_revisions(self._branch.branch, query, True)
128.12.2 by Robert Collins
More no-index error catching.
42
            if terms is not None:
43
                terms = [term[0] for term in terms]
44
            else:
45
                # Should show a 'search is not available' etc box.
46
                terms = []
128.10.5 by Martin Albisetti
* Added logic to suggest search terms while typing
47
230.1.1 by Steve 'Ashcrow' Milner
Updated to follow pep8.
48
        return {'terms': terms}