Esempio n. 1
0
File: search.py Progetto: FND/tank
def list_tags(environ, start_response):
    """
    Plain text list of tags in a certain context.

    If a q query parameter is provided, then that is used to limit
    the search space for tags. For example q=modifier:cdent bag:foobar
    would return tags only from tiddlers in the bag foobar with most
    recent modifier of cdent.
    """
    config = environ['tiddlyweb.config']
    query = environ['tiddlyweb.query'].get('q', [None])[0]

    searcher = get_searcher(config)

    if query:
        # This parsing means that the if there are of the same keyword
        # the last one wins. This is okay because using both would
        # be illogical.
        kwargs = {}
        for match in QUERY_PARSE_RE.finditer(query):
            kwargs[match.group(1)] = match.group(2)
        documents = searcher.documents(**kwargs)
    else:
        documents = searcher.documents()

    # As yet unknown if this will be slow or not.
    set_tags = set()
    for stored_fields in documents:
        set_tags.update(stored_fields['tags'].split(','))

    start_response('200 OK', [('Content-Type', 'text/plain; charset=UTF-8')])

    return '\n'.join(set_tags)
Esempio n. 2
0
def get_indexed_tags(config, query):
    """
    Search the index for the set of tags matching query, or
    all of them.
    """
    searcher = get_searcher(config)

    if query:
        # This parsing means that the if there are of the same keyword
        # the last one wins. This is okay because using both would
        # be illogical.
        kwargs = {}
        for match in QUERY_PARSE_RE.finditer(query):
            kwargs[match.group(1)] = match.group(2)
        documents = searcher.documents(**kwargs)
    else:
        documents = searcher.documents()

    # As yet unknown if this will be slow or not.
    set_tags = set()
    for stored_fields in documents:
        set_tags.update(stored_fields['tags'].split(','))

    return set_tags
Esempio n. 3
0
def full_search(config, query):
    query = query_parse(config, query)
    searcher = get_searcher(config)
    return searcher.search(query)