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 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 #4
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 #5
0
 def generate():
     for event in index_tree(config,
                             from_zip=archive,
                             index_path=index_path):
         yield '%s\n' % event.encode('utf-8')