Example #1
0
def test_basic_index(index_path, project_path):
    from rigidsearch.search import index_tree, get_index

    with open(os.path.join(project_path, 'config.json'), 'rb') as f:
        cfg = json.load(f)

    log = list(index_tree(cfg, index_path=index_path, base_dir=project_path))
    assert log

    content_id = 'e324d4f2e1a8a49c4efcc049b296d7b60bce4e7d'
    content_path = os.path.join(index_path, 'cur', 'content')
    with open(os.path.join(content_path, content_id)) as f:
        contents = f.read().strip()
        assert contents == 'Yo, this should totally be indexed.'

    index = get_index(index_path)
    results = index.search('totally', section='a')
    assert results['items'] == [{
        'excerpt':
        u'Yo, this should <strong class="match term0">'
        u'totally</strong> be indexed',
        'path':
        u'index',
        'title':
        u'Hello World',
        'section':
        'a'
    }]
Example #2
0
def test_basic_index(index_path, project_path):
    from rigidsearch.search import index_tree, get_index

    with open(os.path.join(project_path, 'config.json'), 'rb') as f:
        cfg = json.load(f)

    log = list(index_tree(cfg, index_path=index_path,
                          base_dir=project_path))
    assert log

    content_id = 'e324d4f2e1a8a49c4efcc049b296d7b60bce4e7d'
    content_path = os.path.join(index_path, 'cur', 'content')
    with open(os.path.join(content_path, content_id)) as f:
        contents = f.read().strip()
        assert contents == 'Yo, this should totally be indexed.'

    index = get_index(index_path)
    results = index.search('totally', section='a')
    assert results['items'] == [{
        'excerpt': u'Yo, this should <strong class="match term0">'
                   u'totally</strong> be indexed',
        'path': u'index',
        'title': u'Hello World',
        'section': 'a'
    }]
Example #3
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 #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 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))