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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f00f541542d5dac0c638b5f28d807062d9d3fada8b28685ba0c45ed33f02881
|
|
| MD5 |
c4d8e4b6ed7bf268bb3b439466ef8a00
|
|
| BLAKE2b-256 |
333e9058cb7188d309162daa40160e25c64920b1786d98e432a4fa5a2051ccbf
|
Provenance
The following attestation bundles were made for textsearchpy-1.0.1.tar.gz:
Publisher:
python-publish.yml on KimiJL/textsearchpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
textsearchpy-1.0.1.tar.gz -
Subject digest:
7f00f541542d5dac0c638b5f28d807062d9d3fada8b28685ba0c45ed33f02881 - Sigstore transparency entry: 163991944
- Sigstore integration time:
-
Permalink:
KimiJL/textsearchpy@7e537f273e625c0b46c947dc6c2b97850de705b2 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/KimiJL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7e537f273e625c0b46c947dc6c2b97850de705b2 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb2a0b3829b7e4c6cd20d7eb82eeee32ab84b593c2cb5273104777ae67c27b20
|
|
| MD5 |
7488f97e7e1cc20381b73d1aee8e7086
|
|
| BLAKE2b-256 |
f4ec97f424bcb58f02fb486116294c509b4493406df6f9bef5f552fd72cd03ee
|
Provenance
The following attestation bundles were made for textsearchpy-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on KimiJL/textsearchpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
textsearchpy-1.0.1-py3-none-any.whl -
Subject digest:
fb2a0b3829b7e4c6cd20d7eb82eeee32ab84b593c2cb5273104777ae67c27b20 - Sigstore transparency entry: 163991947
- Sigstore integration time:
-
Permalink:
KimiJL/textsearchpy@7e537f273e625c0b46c947dc6c2b97850de705b2 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/KimiJL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7e537f273e625c0b46c947dc6c2b97850de705b2 -
Trigger Event:
release
-
Statement type: