Giter Club home page Giter Club logo

pyreds's Introduction

pyreds

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

pyreds's People

Contributors

7anshuai avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zhwei820

pyreds's Issues

Install error

$ pip install pyreds
Collecting pyreds
  Downloading pyreds-0.1.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/mq/j45490h51xz9_xk1jfn509dm0000gn/T/pip-build-wx6_04y4/pyreds/setup.py", line 11, in <module>
        from pyreds import __version__
      File "/private/var/folders/mq/j45490h51xz9_xk1jfn509dm0000gn/T/pip-build-wx6_04y4/pyreds/pyreds/__init__.py", line 1, in <module>
        from pyreds.reds import (
      File "/private/var/folders/mq/j45490h51xz9_xk1jfn509dm0000gn/T/pip-build-wx6_04y4/pyreds/pyreds/reds.py", line 5, in <module>
        from nltk.stem.porter import PorterStemmer
    ModuleNotFoundError: No module named 'nltk'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/mq/j45490h51xz9_xk1jfn509dm0000gn/T/pip-build-wx6_04y4/pyreds/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.