示例#1
0
def test_search(database):
    docs = Document.search('')

    assert len(docs) == 3

    docs = Document.search('111')

    assert len(docs) == 2

    docs = Document.search('222')

    assert len(docs) == 1

    docs = Document.search('333')

    assert len(docs) == 0

    docs = Document.search('', filters=[('x', '1')])

    assert len(docs) == 2

    docs = Document.search('', filters=[('x', '1'), ('x', '2')])

    assert len(docs) == 1

    docs = Document.search('', filters=[('x', '1'), ('y', '2')])

    assert len(docs) == 1

    docs = Document.search('111', filters=[('x', '1')])

    assert len(docs) == 1
示例#2
0
def test_facets(database):
    docs = Document.search('')
    facets = Document.facets(docs)

    assert 'x' in facets
    assert 'y' in facets

    docs = Document.search('', filters=[('x', '3')])
    facets = Document.facets(docs, ignores=['x'])

    assert not facets

    docs = Document.search('', filters=[('x', '1')])
    facets = Document.facets(docs, ignores=['x'])

    assert 'y' in facets
示例#3
0
文件: list.py 项目: saalaa/diamond
    def run(self, parent, blocks):
        block = blocks.pop(0)

        (directive, rest) = block.split(' ', 1)

        config = json.loads(rest)

        raw = config.get('raw', False)
        filters = config.get('filters')

        if filters:
            filters = filters.items()

        items = Document.search(filters=filters)

        if items:
            if raw:
                items = ['- [[' + item.slug + ']]' for item in items]
            else:
                items = ['- [' + item.title + '](' + item.slug + ')'
                            for item in items]
        else:
            items = ['- *No results found*']

        blocks.insert(0, '\n'.join(items))
示例#4
0
def search(path=None):
    query = request.args.get('query', '')

    filters = [item.split('=', 1) for item in path.split('/')] \
            if path else []

    ignores = [item[0] for item in filters]

    hits = Document.search(query, filters)
    facets = Document.facets(hits, ignores=ignores)

    return render_template('search.j2', query=query, path=path, hits=hits,
            facets=facets, total=Document.count())