~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/search.py

  • Committer: Steve 'Ashcrow' Milner
  • Date: 2008-10-24 17:15:39 UTC
  • mto: This revision was merged to the branch mainline in revision 231.
  • Revision ID: stevem@gnulinux.net-20081024171539-ei8f8998i3yrtzp4
Added *.log to the ignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
#
20
 
 
21
 
_mod_index = None
22
 
def import_search():
23
 
    global errors, _mod_index, FileTextHit, RevisionHit
24
 
    if _mod_index is not None:
25
 
        return
26
 
    try:
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
30
 
    except ImportError:
31
 
        _mod_index = None
 
20
import sets
 
21
try:
 
22
    from bzrlib.plugins.search import errors
 
23
    from bzrlib.plugins.search import index as _mod_index
 
24
    from bzrlib.plugins.search.index import FileTextHit, RevisionHit
 
25
except ImportError:
 
26
    _mod_index = None
32
27
 
33
28
 
34
29
def search_revisions(branch, query_list, suggest=False):
41
36
    param suggest: Optional flag to request suggestions instead of results
42
37
    return: A list for results, either revision ids or terms
43
38
    """
44
 
    import_search()
45
39
    if _mod_index is None:
46
40
        return None # None indicates could-not-search
47
41
    try:
49
43
    except errors.NoSearchIndex:
50
44
        return None # None indicates could-not-search
51
45
    query = query_list.split(' ')
52
 
    query = [(term,) for term in query]
 
46
    query = [(term) for term in query]
53
47
    revid_list = []
54
48
    index._branch.lock_read()
55
49
 
65
59
                    revid_list.append(result.text_key[1])
66
60
                elif isinstance(result, RevisionHit):
67
61
                    revid_list.append(result.revision_key[0])
68
 
            return list(set(revid_list))
 
62
            return list(sets.Set(revid_list))
69
63
    finally:
70
64
        index._branch.unlock()