Search file name in folders

Create issue
Issue #384 resolved
Former user created an issue

How can i create search using whoosh that will search filename in folders and give result. can anybody help me?

Comments (2)

  1. Xiaosong Rong

    A dame simple example:

    import os
    from whoosh import (index, fields, qparser)
    schema = fields.Schema(
    indexdir = 'indexdir/'                                                                                                                         
    if not os.path.exists(indexdir):
    ix = index.create_in(indexdir, schema)
    writer = ix.writer()
    # the folder that you want to search
    target_path = './'
    for parent, dirs, files in os.walk(target_path):
        for _name in files:
            _path = os.path.join(parent, _name)
            writer.add_document(name=unicode(_name), path=unicode(_path))
    with ix.searcher() as searcher:
        parser = qparser.QueryParser('name', ix.schema)
        # the file that you want to search
        filename = u''
        query = parser.parse(filename)
        results =
        for r in results:
            print r
  2. Log in to comment