2
# Copyright (C) 2008 Canonical Ltd.
3
# (Authored by Martin Albisetti <argentina@gmail.com>)
4
# Copyright (C) 2008 Robert Collins
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
global errors, _mod_index, FileTextHit, RevisionHit
24
if _mod_index is not None:
27
from bzrlib.plugins.search import errors
28
from bzrlib.plugins.search import index as _mod_index
29
from bzrlib.plugins.search.index import FileTextHit, RevisionHit
34
def search_revisions(branch, query_list, suggest=False):
36
Search using bzr-search plugin to find revisions matching the query.
37
This can either suggest query terms, or revision ids.
39
param branch: branch object to search in
40
param query_list: string to search
41
param suggest: Optional flag to request suggestions instead of results
42
return: A list for results, either revision ids or terms
45
if _mod_index is None:
46
return None # None indicates could-not-search
48
index = _mod_index.open_index_branch(branch)
49
except errors.NoSearchIndex:
50
return None # None indicates could-not-search
51
query = query_list.split(' ')
52
query = [(term,) for term in query]
54
index._branch.lock_read()
58
terms = index.suggest(query)
63
for result in index.search(query):
64
if isinstance(result, FileTextHit):
65
revid_list.append(result.text_key[1])
66
elif isinstance(result, RevisionHit):
67
revid_list.append(result.revision_key[0])
68
return list(set(revid_list))
70
index._branch.unlock()