示例#1
0
    def index(self, q='', offset=0, pagesize=15):
        tmpl = lookup.get_template('index.html')
        if not q:
            return tmpl.render(q=q)
        if offset:
            offset = int(offset)
        if pagesize:
            pagesize = int(pagesize)

        result, hits, doccount = [], 0, 0
        querystring = q.encode('utf8') if isinstance(q, unicode) else q
        doccount, mset = search(db_path, querystring, offset, pagesize)
        hits = mset.get_matches_estimated()
        for match in mset:
            item = get_item(match)
            if item:
                result.append(item)

        pages = calculate_pages(hits, offset, pagesize)

        return tmpl.render(q=q,
                           result=result,
                           hits=hits,
                           doccount=doccount,
                           pages=pages,
                           )
示例#2
0
    def index(self, q='', offset=0, pagesize=15):
        tmpl = lookup.get_template('index.html')
        if not q:
            return tmpl.render(q=q)
        if offset:
            offset = int(offset)
        if pagesize:
            pagesize = int(pagesize)

        result, hits, doccount = [], 0, 0
        querystring = q.encode('utf8') if isinstance(q, unicode) else q
        doccount, mset = search(db_path, querystring, offset, pagesize)
        hits = mset.get_matches_estimated()
        for match in mset:
            item = get_item(match)
            if item:
                result.append(item)

        pages = calculate_pages(hits, offset, pagesize)

        return tmpl.render(
            q=q,
            result=result,
            hits=hits,
            doccount=doccount,
            pages=pages,
        )
示例#3
0
def print_search(dbpath, querystring, offset=0, pagesize=10):
    doccount, mset = search(dbpath, querystring, offset, pagesize)
    for match in mset:
        meta = json.loads(match.document.get_data())
        logger.info('[%0*d]:%s',
                    int(math.log(pagesize, 10)+1),
                    match.rank + 1,
                    #match.docid,
                    '\n'.join([i.replace('/home/huanghao/Documents/ebook/', '') for i in meta['paths']]))
        logger.debug(json.dumps(meta, indent=4))
    logger.info('About %s results in %s docs',
                mset.get_matches_estimated(),
                doccount)
示例#4
0
def print_search(dbpath, querystring, offset=0, pagesize=10):
    doccount, mset = search(dbpath, querystring, offset, pagesize)
    for match in mset:
        meta = json.loads(match.document.get_data())
        logger.info(
            '[%0*d]:%s',
            int(math.log(pagesize, 10) + 1),
            match.rank + 1,
            #match.docid,
            '\n'.join([
                i.replace('/home/huanghao/Documents/ebook/', '')
                for i in meta['paths']
            ]))
        logger.debug(json.dumps(meta, indent=4))
    logger.info('About %s results in %s docs', mset.get_matches_estimated(),
                doccount)