Example #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)
Example #2
0
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')
Example #3
0
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)
Example #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']))
Example #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)
Example #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']
        ))
Example #7
0
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)
Example #8
0
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))