コード例 #1
0
ファイル: app.py プロジェクト: romanchyla/dumean
def suggest(app_name):
    worker = None
    if app_name not in _applications:
        module = __import__("dumean.apps.%s" % app_name, globals=globals(), locals=locals())
        if module is None or not hasattr(module.apps, app_name):
            raise Exception("There is no handler for: %s" % app_name)
        get_worker = getattr(getattr(module.apps, app_name), 'get_worker')
        _applications[app_name] = get_worker()

    worker = _applications[app_name]
    
    dumean.start_jvm()
    dumean.attach()
    
    query = None
    if request.args['term']:
        query = request.args
    else:
        return render_template('404.html'), 404
    
    start = time.time()
    if 'term' in query and len(query['term']):
        if 'data' in query: # 2nd level lookup
            data = worker.get_similar(query['term'], data=query['data'])
        else:
            data = worker.get_suggestions(query['term'])
    else:
        data = []

    if data:
        t = '<%.6f s>' % (time.time() - start)
        data.append({'label': t, 'value': t})

    return worker.format(data), 200
コード例 #2
0
ファイル: whisperer.py プロジェクト: romanchyla/dumean
    def __init__(self):
        """When instantiated, it does nothing besides loading the java VM
        @see: self.open()
        """

        global dumeanj
        self.opened = False
        self.indexer = None
        self.worker = None
        self.searcher = None
        self.index_dir = None

        if not dumeanj:
            dumeanj = dumean.get_java_module()

        dumean.start_jvm()