Skip to main content

Simple full text search module for Python, backed by Redis

Project description

https://travis-ci.org/7anshuai/pyreds.svg?branch=master

reds is a light-weight Redis Search for Node.js.

pyreds is a Python port of reds.

Installation

pyreds requires a running Redis server. See Redis’s quickstart for installation instructions.

To install pyreds, simply:

$ pip install pyreds

You may need install NLTK Data:

>>> import nltk
>>> nltk.download('stopwords')

Getting Started

The first thing you’ll want to do is create a Search instance, which allow you to pass a key, used for namespacing within Redis so that you may have several searches in the same db.

>>> import pyreds
>>> search = pyreds.create_search('pets')

pyreds acts against arbitrary numeric or string based ids, so you could utilize this library with essentially anything you wish, even combining data stores. The following example just uses a list for our “database”, containing some strings, which we add to pyreds by calling Search#index() padding the body of text and an id of some kind, in this case the index.

>>> strs = []
>>> strs.append('Tobi wants four dollars')
>>> strs.append('Tobi only wants $4')
>>> strs.append('Loki is really fat')
>>> strs.append('Loki, Jane, and Tobi are ferrets')
>>> strs.append('Manny is a cat')
>>> strs.append('Luna is a cat')
>>> strs.append('Mustachio is a cat')
>>> for i, v in enumerate(strs):
...     search.index(v, i)

To perform a query against pyreds simply invoke Search#query() with a string, which return a Query instance. Then invoke Query#end(), which return a list of ids when present, or an empty list otherwise.

>>> ids = search.query('Tobi dollars').end()
>>> print('Search results for "Tobi dollars"'))
>>> for id in ids:
...     print('  - {}'.format(strs[id]))

By default pyreds performs an intersection of the search words. The previous example would yield the following output since only one string contains both “Tobi” and “dollars”:

Search results for "Tobi dollars":
    - Tobi wants four dollars

We can tweak pyreds to perform a union by passing either “union” or “or” to Search#type() between Search#query() and Query#end(), indicating that any of the constants computed may be present for the id to match.

>>> ids = search.query('tobi dollars').type('or').end()
>>> print('Search results for "Tobi dollars"'))
>>> for id in ids:
...     print('  - {}'.format(strs[id]))

The union search would yield the following since three strings contain either “Tobi” or “dollars”:

Search results for "tobi dollars":
    - Tobi wants four dollars
    - Tobi only wants $4
    - Loki, Jane, and Tobi are ferrets

API

>>> search = pyreds.create_search(key)
>>> search.index(text, id)
>>> search.remove(id)
>>> query = search.query(text[, type]) # will return a `Query` instance
>>>
>>> query.between(start, stop)
>>> query.type(type)
>>> query.end()

LICENSE

The MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyreds-0.1.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distributions

pyreds-0.1.4-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

pyreds-0.1.4-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyreds-0.1.4.tar.gz.

File metadata

  • Download URL: pyreds-0.1.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.6

File hashes

Hashes for pyreds-0.1.4.tar.gz
Algorithm Hash digest
SHA256 91551c52709c510e7732bfa91680c309c681f3cb4772a5de4803b4fa21496d31
MD5 1eba13c2e486cf1891c907c06b9c567b
BLAKE2b-256 7e142981e18ce6965521f39cae5c5e7bedd4f8b29bbf6779de3c02f6b857784a

See more details on using hashes here.

File details

Details for the file pyreds-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pyreds-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.6

File hashes

Hashes for pyreds-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3982cc2a9f2dc1272d552af5e6592dfe85494d364d251fe1ee4397bae782b3ae
MD5 64676a0e5c7e28a5238514008d1846fb
BLAKE2b-256 0994229947473d904434fc7983473a81ace5c1757449b1fc64370ff1eb09ef3d

See more details on using hashes here.

File details

Details for the file pyreds-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: pyreds-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.6

File hashes

Hashes for pyreds-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 76c867dd42e9d2651bdb425d8d8711d6d214f1c591437b0ab776406ac4aa7eb9
MD5 8ca08fb73f244a8bf5ee3fbe6dad7c88
BLAKE2b-256 44a1b772ef9791c031e9c9873f5a8609a10d127ba3c3e19c0a84b0abeae4854a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page