예제 #1
0
def index_folder_cmd(ctx, config, index_path, save_zip):
    """Indexes a path."""
    from rigidsearch.search import index_tree, get_index_path
    index_path = get_index_path(index_path=index_path, app=ctx.app)
    for event in index_tree(json.load(config), index_zip=save_zip,
                            index_path=index_path):
        click.echo(event)
예제 #2
0
파일: api.py 프로젝트: robopsi/rigidsearch
def process_zip_for_index():
    if not safe_str_cmp(request.form.get('secret', ''),
                        current_app.config['SEARCH_INDEX_SECRET']):
        abort(403)

    index_path = get_index_path()

    config = json.load(request.files['config'])

    archive = release_file(request, 'archive')

    try:
        shutil.rmtree(index_path)
    except (OSError, IOError):
        pass

    def generate():
        for event in index_tree(config,
                                from_zip=archive,
                                index_path=index_path):
            yield '%s\n' % event.encode('utf-8')

    return Response(generate(),
                    direct_passthrough=True,
                    headers={'X-Accel-Buffering': 'no'},
                    mimetype='text/plain')
예제 #3
0
파일: api.py 프로젝트: robopsi/rigidsearch
def update_index():
    if not safe_str_cmp(request.form.get('secret', ''),
                        current_app.config['SEARCH_INDEX_SECRET']):
        abort(403)
    index_path = get_index_path()
    put_index(index_path, request.files['archive'])
    return jsonify(okay=True)
예제 #4
0
def search_cmd(ctx, query, section, index_path):
    """Triggers a search from the command line."""
    from rigidsearch.search import get_index, get_index_path

    index_path = get_index_path(app=ctx.app)
    index = get_index(index_path)
    results = index.search(query, section=section)
    for result in results['items']:
        click.echo('%s (%s)' % (result['path'], result['title']))
예제 #5
0
def index_folder_cmd(ctx, config, index_path, save_zip):
    """Indexes a path."""
    from rigidsearch.search import index_tree, get_index_path
    index_path = get_index_path(index_path=index_path, app=ctx.app)
    try:
        shutil.rmtree(index_path)
    except (OSError, IOError):
        pass
    for event in index_tree(json.load(config),
                            index_zip=save_zip,
                            index_path=index_path):
        click.echo(event)
예제 #6
0
def search_cmd(ctx, query, section, index_path):
    """Triggers a search from the command line."""
    from rigidsearch.search import get_index, get_index_path

    index_path = get_index_path(app=ctx.app)
    index = get_index(index_path)
    results = index.search(query, section=section)
    for result in results['items']:
        click.echo('%s (%s)' % (
            result['path'],
            result['title']
        ))
예제 #7
0
파일: api.py 프로젝트: robopsi/rigidsearch
def delete_index():
    if not safe_str_cmp(request.form.get('secret', ''),
                        current_app.config['SEARCH_INDEX_SECRET']):
        abort(403)

    index_path = get_index_path()
    if index_path is not None:
        try:
            shutil.rmtree(index_path)
        except (OSError, IOError):
            pass
    deleted = not os.path.isdir(index_path)
    if deleted:
        return Response(status=204)
    else:
        return Response(status=500)
예제 #8
0
파일: api.py 프로젝트: robopsi/rigidsearch
def search():
    q = request.args.get('q') or u''
    page = request.args.get('page', type=int, default=1)
    per_page = request.args.get('per_page', type=int, default=20)
    excerpt_fragmenter = request.args.get('excerpt_fragmenter')
    excerpt_maxchars = request.args.get('excerpt_maxchars', type=int)
    excerpt_surround = request.args.get('excerpt_surround', type=int)
    section = request.args.get('section') or 'generic'

    index_path = get_index_path()
    return jsonify(
        get_index(index_path).search(q,
                                     section,
                                     page=page,
                                     per_page=per_page,
                                     excerpt_fragmenter=excerpt_fragmenter,
                                     excerpt_maxchars=excerpt_maxchars,
                                     excerpt_surround=excerpt_surround))