Skip to main content

In memory text search engine written in python

Project description

TextSearchPy

TextSearchPy is a high performance, easy to use, in-memory text search engine library written in Python.

Install

pip install textsearchpy

Quickstart

Default Index is created with SimpleTokenizer and LowerCaseNormalizer

from textsearchpy import Index, Document

# create index with default settings
index = Index()

# add to index
index.append(["The quick brown fox"])

# alternatively, create Document object and append
doc = Document(text="jumps over the lazy dog")
index.append([doc])

# search with query string, returns list of Document objects
print(index.search("fox"))
print(index.search("fox OR dog"))
print(index.search("fox AND dog"))
print(index.search("fox NOT quick"))

# shows how input text is tokenized & normalized
print(index.text_to_index_tokens("The quick brown fox"))

Query Syntax

Query can be written in string format (shown in quickstart) or by creating different Query objects

query = "fox"

query = "fox AND dog NOT quick"

query = "(fox OR dog) AND (quick OR lazy)"

# proximity search with distance of 1
query = '"quick fox"~1'

Supported Query Types:

TermQuery - query with single token

from textsearchpy.query import TermQuery

query = "fox"
query = TermQuery(term="fox)

BooleanQuery - sub queries with boolean condition

Clause - "SHOULD", "MUST", "MUST_NOT"

BooleanClause accept any query type, thus it is possible to create a tree of grouped boolean queries

from textsearchpy.query import TermQuery, BooleanClause, BooleanQuery

query = "(fox OR dog) AND (quick NOT lazy)"

term_1 = TermQuery(term="fox")
term_2 = TermQuery(term="dog")
query_left = BooleanQuery(
    clauses=[
        BooleanClause(query=term_1, clause="SHOULD"),
        BooleanClause(query=term_2, clause="SHOULD"),
    ]
)

term_3 = TermQuery(term="quick")
term_4 = TermQuery(term="lazy")
query_right = BooleanQuery(
    clauses=[
        BooleanClause(query=term_3, clause="SHOULD"),
        BooleanClause(query=term_4, clause="MUST_NOT"),
    ]
)

final_query = BooleanQuery(
    clauses=[
        BooleanClause(query=query_left, clause="MUST"),
        BooleanClause(query=query_right, clause="MUST"),
    ]
)

PhraseQuery - multi term query with option to set proximity distance

by default, terms in phrase is not order sensitive

the distance represents a term based edit distance, i.e. how many other terms are allowed within the boundry of the search terms

from textsearchpy.query import PhraseQuery

query = '"brown fox"'
query = PhraseQuery(terms=["brown", "fox"], distance=0)
# to enforce order sensitivity
query = PhraseQuery(terms=["brown", "fox"], distance=0, ordered=True)


query = '"jumps dog"~3'
query = PhraseQuery(terms=["jumps", "dog"], distance=3)
# to enforce order sensitivity
query = PhraseQuery(terms=["jumps", "dog"], distance=3, ordered=True)

# any two additional terms are allowed between these three terms for searching
query = '"jumps lazy dog"~2'

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

textsearchpy-1.0.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textsearchpy-1.0.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file textsearchpy-1.0.1.tar.gz.

File metadata

  • Download URL: textsearchpy-1.0.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for textsearchpy-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7f00f541542d5dac0c638b5f28d807062d9d3fada8b28685ba0c45ed33f02881
MD5 c4d8e4b6ed7bf268bb3b439466ef8a00
BLAKE2b-256 333e9058cb7188d309162daa40160e25c64920b1786d98e432a4fa5a2051ccbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for textsearchpy-1.0.1.tar.gz:

Publisher: python-publish.yml on KimiJL/textsearchpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file textsearchpy-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: textsearchpy-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for textsearchpy-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb2a0b3829b7e4c6cd20d7eb82eeee32ab84b593c2cb5273104777ae67c27b20
MD5 7488f97e7e1cc20381b73d1aee8e7086
BLAKE2b-256 f4ec97f424bcb58f02fb486116294c509b4493406df6f9bef5f552fd72cd03ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for textsearchpy-1.0.1-py3-none-any.whl:

Publisher: python-publish.yml on KimiJL/textsearchpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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