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
from bzrlib.plugins.search import errors
24
from bzrlib.plugins.search import index as _mod_index
25
from bzrlib.plugins.search.index import FileTextHit, RevisionHit
29
def search_revisions(branch, query_list, suggest=False):
31
Search using bzr-search plugin to find revisions matching the query.
32
This can either suggest query terms, or revision ids.
34
param branch: branch object to search in
35
param query_list: string to search
36
param suggest: Optional flag to request suggestions instead of results
37
return: A list for results, either revision ids or terms
39
if _mod_index is None:
40
return None # None indicates could-not-search
42
index = _mod_index.open_index_branch(branch)
43
except errors.NoSearchIndex:
44
return None # None indicates could-not-search
45
query = query_list.split(' ')
46
query = [(term,) for term in query]
48
index._branch.lock_read()
52
terms = index.suggest(query)
57
for result in index.search(query):
58
if isinstance(result, FileTextHit):
59
revid_list.append(result.text_key[1])
60
elif isinstance(result, RevisionHit):
61
revid_list.append(result.revision_key[0])
62
return list(sets.Set(revid_list))
64
index._branch.unlock()