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
22
global errors, _mod_index, FileTextHit, RevisionHit
23
if _mod_index is not None:
26
from bzrlib.plugins.search import errors
27
from bzrlib.plugins.search import index as _mod_index
28
from bzrlib.plugins.search.index import FileTextHit, RevisionHit
33
def search_revisions(branch, query_list, suggest=False):
35
Search using bzr-search plugin to find revisions matching the query.
36
This can either suggest query terms, or revision ids.
38
param branch: branch object to search in
39
param query_list: string to search
40
param suggest: Optional flag to request suggestions instead of results
41
return: A list for results, either revision ids or terms
44
if _mod_index is None:
45
return None # None indicates could-not-search
47
index = _mod_index.open_index_branch(branch)
48
except errors.NoSearchIndex:
49
return None # None indicates could-not-search
50
query = query_list.split(' ')
51
query = [(term,) for term in query]
53
index._branch.lock_read()
57
terms = index.suggest(query)
62
for result in index.search(query):
63
if isinstance(result, FileTextHit):
64
revid_list.append(result.text_key[1])
65
elif isinstance(result, RevisionHit):
66
revid_list.append(result.revision_key[0])
67
return list(set(revid_list))
69
index._branch.unlock()