Usage Examples — metaindex documentation

# Usage Examples

## Command line usage

### Index some directories

To index you `Documents` and `Pictures` folder recursively:

    metaindex index -r -i ~/Documents ~/Pictures

### Reindex all files

To only update the metadata from all known files:

    metaindex index -i

### Find all files

List all files that are in cache:

    metaindex find

### Find file by mimetype

Searching for all `image/*` mimetypes can be accomplished by this:

    metaindex find mimetype:^image/

### Listing metadata

To list all metadata tags and values of all odt files:

    metaindex find -t -- "filename:odt$"

List the resolutions of all files that have the `resolution` metadata tag:

    metaindex find -t resolution -- "resolution?"

## Developer examples

### Index some files

You can use metaindexer’s index facility without using the cache:

     1"""How to index some files using metaindex"""
     2import sys
     3from pathlib import Path
     4
     5import metaindex
     6
     7
     8def index_files(files):
     9    """Just run the indexer on these files"""
    10    # we need at least the basic configuration
    11    config = metaindex.Configuration()
    12
    13    # if you actually want to also load the user's config file/preferences,
    14    # do this instead:
    15    #   import metaindex.configuration
    16    #   config = metaindex.configuration.load()
    17
    18    # find and load all additional humanizers and indexers
    19    config.load_addons()
    20
    21    # loads the extra mimetypes from the configuration, if there are any
    22    config.load_mimetypes()
    23
    24    results = metaindex.index_files(files, config)
    25    # index_files returns a list of each one IndexerResult per file
    26    assert all(isinstance(r, metaindex.IndexerResult) for r in results)
    27
    28    # return the CacheEntry per IndexerResult (i.e. per file), but only if
    29    # that file's index run was successful
    30    return [result.info
    31            for result in results
    32            if result.success]
    33
    34
    35if __name__ == '__main__':
    36    # run the indexer on all files that were provided as commandline parameters
    37    userfiles = [Path(p) for p in sys.argv[1:]]
    38    print(index_files(userfiles))