~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/views/search.py

  • Committer: Tarmac
  • Author(s): Aaron Bentley
  • Date: 2013-03-28 18:56:12 UTC
  • mfrom: (179.3.4 remove-xappy)
  • Revision ID: tarmac-20130328185612-6f635k1h2wxh4eaw
[r=sinzui][bug=1099856][author=abentley] Remove Xapian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from pyramid.httpexceptions import HTTPFound
7
7
from webob import Response
8
8
 
9
 
from charmworld.jobs.config import CHARM_INDEX_DIR
10
9
from charmworld.search import ElasticSearchClient
11
 
from charmworld.views import SEARCH_FIELDS
12
10
from charmworld.views.helpers import result_sorter
13
 
from charmworld.utils import (
14
 
    get_ini,
15
 
    Timer,
16
 
)
17
 
 
18
 
 
19
 
def do_xappy_search(terms, allow_all_fields=False):
20
 
    import xappy
21
 
    searcher = xappy.SearchConnection(CHARM_INDEX_DIR)
22
 
    if allow_all_fields:
23
 
        deny = []
24
 
    else:
25
 
        deny = ['relations', 'config', 'changes']
26
 
    query = searcher.query_parse(
27
 
        terms,
28
 
        allow=SEARCH_FIELDS,
29
 
        allow_wildcards=True,
30
 
        default_deny=deny)
31
 
 
32
 
    with Timer() as timer:
33
 
        results = query.search(0, 30)
34
 
    search_time = u"%.5f" % timer.duration()
35
 
    return {"results": results,
36
 
            "search_time": search_time,
37
 
            "charm_total": searcher.get_doccount()}
38
 
 
39
 
 
40
 
def do_search(terms, allow_all_fields=False):
41
 
    client = ElasticSearchClient.from_settings(get_ini())
42
 
    return client.search(terms, allow_all_fields)
 
11
from charmworld.utils import get_ini
 
12
 
 
13
 
 
14
def do_search(terms):
 
15
    return ElasticSearchClient.from_settings(get_ini()).search(terms)
43
16
 
44
17
 
45
18
@view_config(
49
22
    if not "search_text" in request.params:
50
23
        url = request.route_url("home")
51
24
        return HTTPFound(location=url)
52
 
    # XXX bug=1099856 jcsackett Jan 1 2012: `allow_all_fields` must be true
53
 
    # for the template, else the rendering engine blows up on
54
 
    # `results.matches_human_readable_estimate`
55
 
    search = do_search(request.params["search_text"], allow_all_fields=True)
 
25
    search = do_search(request.params["search_text"])
56
26
    return dict((key, value) for key, value in search.items()
57
27
                if key != 'matches')
58
28