예제 #1
0
파일: pager.py 프로젝트: pombredanne/helmut
 def query(self, **kwargs):
     if len(self.facets):
         kwargs['facet'] = 'true'
         if not 'facet_limit' in kwargs:
             kwargs['facet_limit'] = 20
         kwargs['facet_field'] = self.facets
     return query(g.solr, self.q or '*:*',
                  filters=self.filters,
                  start=self.offset,
                  rows=self.limit,
                  **kwargs)
예제 #2
0
파일: web.py 프로젝트: pombredanne/helmut
def _query(q):
    if isinstance(q, basestring):
        q = {'query': q}
    try:
        limit = max(1, min(100, int(q.get('limit'))))
    except ValueError: limit = 5
    except TypeError: limit = 5

    filters = [(p.get('p'), p.get('v', '*')) for p in \
               q.get('properties', []) if 'p' in p]
    types = q.get('types')
    if types is not None:
        if isinstance(types, basestring):
            types = [types]
        types = map(lambda t: t.strip().lstrip('/'), types)
        filters.extend([('__type__', t) for t in types])
        # todo: implement types_strict
    results = query(g.solr, q.get('query'), filters=filters, rows=limit)
    matches = []
    for result in results.get('response', {}).get('docs', []):
        id = url_for('entity', type=result.get('__type__'),
                key=result.get('__key__'))
        uri = url_for('entity', type=result.get('__type__'),
                key=result.get('__key__'), _external=True)
        matches.append({
            'name': result.get('title'),
            'score': result.get('score') * 2000,
            'type': [{
                'id': '/' + result.get('__type__'),
                'name': result.get('__type__')
                }],
            'id': id,
            'uri': uri,
            'match': False
            })

    return {
        'result': matches, 
        'num': results.get('numFound')
        }