mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
removed unused code for deprecated text search (#322)
* removed unused code for depricated text search Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * updated changelog Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> --------- Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
384b091d74
commit
c69272f6a2
@ -27,6 +27,7 @@ For reference, the possible headings are:
|
||||
|
||||
## [2.2.4] - 2023-15-02
|
||||
* **Changed** migrated dependency management to poetry
|
||||
* **Removed** removed unused text_search related code
|
||||
|
||||
## [2.2.3] - 2023-14-02
|
||||
* **Fixed** fixed voting/election backward compatibility issue (using planetmint-transactions >= 0.7.0) on the 2.2 main branch
|
||||
|
@ -116,41 +116,6 @@ def get_txids_filtered(conn, asset_ids, operation=None, last_tx=None):
|
||||
return (elem["id"] for elem in cursor)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def text_search(
|
||||
conn,
|
||||
search,
|
||||
*,
|
||||
language="english",
|
||||
case_sensitive=False,
|
||||
diacritic_sensitive=False,
|
||||
text_score=False,
|
||||
limit=0,
|
||||
table="assets"
|
||||
):
|
||||
cursor = conn.run(
|
||||
conn.collection(table)
|
||||
.find(
|
||||
{
|
||||
"$text": {
|
||||
"$search": search,
|
||||
"$language": language,
|
||||
"$caseSensitive": case_sensitive,
|
||||
"$diacriticSensitive": diacritic_sensitive,
|
||||
}
|
||||
},
|
||||
{"score": {"$meta": "textScore"}, "_id": False},
|
||||
)
|
||||
.sort([("score", {"$meta": "textScore"})])
|
||||
.limit(limit)
|
||||
)
|
||||
|
||||
if text_score:
|
||||
return cursor
|
||||
|
||||
return (_remove_text_score(obj) for obj in cursor)
|
||||
|
||||
|
||||
def _remove_text_score(asset):
|
||||
asset.pop("score", None)
|
||||
return asset
|
||||
|
@ -243,47 +243,6 @@ def get_txids_filtered(connection, asset_id, operation=None):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def text_search(
|
||||
conn,
|
||||
search,
|
||||
*,
|
||||
language="english",
|
||||
case_sensitive=False,
|
||||
diacritic_sensitive=False,
|
||||
text_score=False,
|
||||
limit=0,
|
||||
table=None
|
||||
):
|
||||
"""Return all the assets that match the text search.
|
||||
|
||||
The results are sorted by text score.
|
||||
For more information about the behavior of text search on MongoDB see
|
||||
https://docs.mongodb.com/manual/reference/operator/query/text/#behavior
|
||||
|
||||
Args:
|
||||
search (str): Text search string to query the text index
|
||||
language (str, optional): The language for the search and the rules for
|
||||
stemmer and tokenizer. If the language is ``None`` text search uses
|
||||
simple tokenization and no stemming.
|
||||
case_sensitive (bool, optional): Enable or disable case sensitive
|
||||
search.
|
||||
diacritic_sensitive (bool, optional): Enable or disable case sensitive
|
||||
diacritic search.
|
||||
text_score (bool, optional): If ``True`` returns the text score with
|
||||
each document.
|
||||
limit (int, optional): Limit the number of returned documents.
|
||||
|
||||
Returns:
|
||||
:obj:`list` of :obj:`dict`: a list of assets
|
||||
|
||||
Raises:
|
||||
OperationError: If the backend does not support text search
|
||||
"""
|
||||
|
||||
raise OperationError("This query is only supported when running " "Planetmint with MongoDB as the backend.")
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_latest_block(conn):
|
||||
"""Get the latest commited block i.e. block with largest height"""
|
||||
|
@ -257,25 +257,6 @@ def get_txids_filtered(connection, asset_ids: list[str], operation: str = "", la
|
||||
return ids
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def text_search(conn, search, table=TARANT_TABLE_ASSETS, limit=0):
|
||||
pattern = ".{}.".format(search)
|
||||
field_no = 1 if table == TARANT_TABLE_ASSETS else 2 # 2 for meta_data
|
||||
res = conn.run(conn.space(table).call("indexed_pattern_search", (table, field_no, pattern)))
|
||||
|
||||
to_return = []
|
||||
|
||||
if len(res[0]): # NEEDS BEAUTIFICATION
|
||||
if table == TARANT_TABLE_ASSETS:
|
||||
for result in res[0]:
|
||||
to_return.append({"data": json.loads(result[0])["data"], "id": result[1]})
|
||||
else:
|
||||
for result in res[0]:
|
||||
to_return.append({TARANT_TABLE_META_DATA: json.loads(result[1]), "id": result[0]})
|
||||
|
||||
return to_return if limit == 0 else to_return[:limit]
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def get_owned_ids(connection, owner: str) -> list[DbTransaction]:
|
||||
outputs = connection.run(connection.space(TARANT_TABLE_OUTPUT).select(owner, index="public_keys"))
|
||||
|
@ -496,18 +496,6 @@ class Planetmint(object):
|
||||
logger.warning("Invalid transaction (%s): %s", type(e).__name__, e)
|
||||
return False
|
||||
|
||||
def text_search(self, search, *, limit=0, table="assets"):
|
||||
"""Return an iterator of assets that match the text search
|
||||
|
||||
Args:
|
||||
search (str): Text search string to query the text index
|
||||
limit (int, optional): Limit the number of returned documents.
|
||||
|
||||
Returns:
|
||||
iter: An iterator of assets that match the text search.
|
||||
"""
|
||||
return backend.query.text_search(self.connection, search, limit=limit, table=table)
|
||||
|
||||
def get_assets(self, asset_ids) -> list[Asset]:
|
||||
"""Return a list of assets that match the asset_ids
|
||||
|
||||
|
@ -80,90 +80,6 @@
|
||||
# for asset in assets:
|
||||
# assert query.get_asset(conn, asset['id'])
|
||||
#
|
||||
# @pytest.mark.skip
|
||||
# @pytest.mark.parametrize('table', ['assets', 'metadata'])
|
||||
# def test_text_search(table):
|
||||
# from planetmint.backend import connect, query
|
||||
# conn = connect()
|
||||
#
|
||||
# # Example data and tests cases taken from the mongodb documentation
|
||||
# # https://docs.mongodb.com/manual/reference/operator/query/text/
|
||||
# objects = [
|
||||
# {'id': 1, 'subject': 'coffee', 'author': 'xyz', 'views': 50},
|
||||
# {'id': 2, 'subject': 'Coffee Shopping', 'author': 'efg', 'views': 5},
|
||||
# {'id': 3, 'subject': 'Baking a cake', 'author': 'abc', 'views': 90},
|
||||
# {'id': 4, 'subject': 'baking', 'author': 'xyz', 'views': 100},
|
||||
# {'id': 5, 'subject': 'Café Con Leche', 'author': 'abc', 'views': 200},
|
||||
# {'id': 6, 'subject': 'Сырники', 'author': 'jkl', 'views': 80},
|
||||
# {'id': 7, 'subject': 'coffee and cream', 'author': 'efg', 'views': 10},
|
||||
# {'id': 8, 'subject': 'Cafe con Leche', 'author': 'xyz', 'views': 10}
|
||||
# ]
|
||||
#
|
||||
# # insert the assets
|
||||
# conn.db[table].insert_many(deepcopy(objects), ordered=False)
|
||||
#
|
||||
# # test search single word
|
||||
# assert list(query.text_search(conn, 'coffee', table=table)) == [
|
||||
# {'id': 1, 'subject': 'coffee', 'author': 'xyz', 'views': 50},
|
||||
# {'id': 2, 'subject': 'Coffee Shopping', 'author': 'efg', 'views': 5},
|
||||
# {'id': 7, 'subject': 'coffee and cream', 'author': 'efg', 'views': 10},
|
||||
# ]
|
||||
#
|
||||
# # match any of the search terms
|
||||
# assert list(query.text_search(conn, 'bake coffee cake', table=table)) == [
|
||||
# {'author': 'abc', 'id': 3, 'subject': 'Baking a cake', 'views': 90},
|
||||
# {'author': 'xyz', 'id': 1, 'subject': 'coffee', 'views': 50},
|
||||
# {'author': 'xyz', 'id': 4, 'subject': 'baking', 'views': 100},
|
||||
# {'author': 'efg', 'id': 2, 'subject': 'Coffee Shopping', 'views': 5},
|
||||
# {'author': 'efg', 'id': 7, 'subject': 'coffee and cream', 'views': 10}
|
||||
# ]
|
||||
#
|
||||
# # search for a phrase
|
||||
# assert list(query.text_search(conn, '\"coffee shop\"', table=table)) == [
|
||||
# {'id': 2, 'subject': 'Coffee Shopping', 'author': 'efg', 'views': 5},
|
||||
# ]
|
||||
#
|
||||
# # exclude documents that contain a term
|
||||
# assert list(query.text_search(conn, 'coffee -shop', table=table)) == [
|
||||
# {'id': 1, 'subject': 'coffee', 'author': 'xyz', 'views': 50},
|
||||
# {'id': 7, 'subject': 'coffee and cream', 'author': 'efg', 'views': 10},
|
||||
# ]
|
||||
#
|
||||
# # search different language
|
||||
# assert list(query.text_search(conn, 'leche', language='es', table=table)) == [
|
||||
# {'id': 5, 'subject': 'Café Con Leche', 'author': 'abc', 'views': 200},
|
||||
# {'id': 8, 'subject': 'Cafe con Leche', 'author': 'xyz', 'views': 10}
|
||||
# ]
|
||||
#
|
||||
# # case and diacritic insensitive search
|
||||
# assert list(query.text_search(conn, 'сы́рники CAFÉS', table=table)) == [
|
||||
# {'id': 6, 'subject': 'Сырники', 'author': 'jkl', 'views': 80},
|
||||
# {'id': 5, 'subject': 'Café Con Leche', 'author': 'abc', 'views': 200},
|
||||
# {'id': 8, 'subject': 'Cafe con Leche', 'author': 'xyz', 'views': 10}
|
||||
# ]
|
||||
#
|
||||
# # case sensitive search
|
||||
# assert list(query.text_search(conn, 'Coffee', case_sensitive=True, table=table)) == [
|
||||
# {'id': 2, 'subject': 'Coffee Shopping', 'author': 'efg', 'views': 5},
|
||||
# ]
|
||||
#
|
||||
# # diacritic sensitive search
|
||||
# assert list(query.text_search(conn, 'CAFÉ', diacritic_sensitive=True, table=table)) == [
|
||||
# {'id': 5, 'subject': 'Café Con Leche', 'author': 'abc', 'views': 200},
|
||||
# ]
|
||||
#
|
||||
# # return text score
|
||||
# assert list(query.text_search(conn, 'coffee', text_score=True, table=table)) == [
|
||||
# {'id': 1, 'subject': 'coffee', 'author': 'xyz', 'views': 50, 'score': 1.0},
|
||||
# {'id': 2, 'subject': 'Coffee Shopping', 'author': 'efg', 'views': 5, 'score': 0.75},
|
||||
# {'id': 7, 'subject': 'coffee and cream', 'author': 'efg', 'views': 10, 'score': 0.75},
|
||||
# ]
|
||||
#
|
||||
# # limit search result
|
||||
# assert list(query.text_search(conn, 'coffee', limit=2, table=table)) == [
|
||||
# {'id': 1, 'subject': 'coffee', 'author': 'xyz', 'views': 50},
|
||||
# {'id': 2, 'subject': 'Coffee Shopping', 'author': 'efg', 'views': 5},
|
||||
# ]
|
||||
#
|
||||
# @pytest.mark.skip
|
||||
# def test_write_metadata():
|
||||
|
@ -67,30 +67,6 @@ class TestBigchainApi(object):
|
||||
with pytest.raises(OperationError):
|
||||
b.store_bulk_transactions([tx])
|
||||
|
||||
def test_text_search(self, b, alice):
|
||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||
|
||||
if isinstance(b.connection, TarantoolDBConnection):
|
||||
warnings.warn(" :::::: This function is used only with :::::: ")
|
||||
return
|
||||
|
||||
# define the assets
|
||||
asset1 = {"data": multihash(marshal({"msg": "Planetmint 1"}))}
|
||||
asset2 = {"data": multihash(marshal({"msg": "Planetmint 2"}))}
|
||||
asset3 = {"data": multihash(marshal({"msg": "Planetmint 3"}))}
|
||||
|
||||
# create the transactions
|
||||
tx1 = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[asset1]).sign([alice.private_key])
|
||||
tx2 = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[asset2]).sign([alice.private_key])
|
||||
tx3 = Create.generate([alice.public_key], [([alice.public_key], 1)], assets=[asset3]).sign([alice.private_key])
|
||||
|
||||
# write the transactions to the DB
|
||||
b.store_bulk_transactions([tx1, tx2, tx3])
|
||||
|
||||
# get the assets through text search
|
||||
assets = list(b.text_search("planetmint"))
|
||||
assert len(assets) == 0
|
||||
|
||||
@pytest.mark.usefixtures("inputs")
|
||||
def test_non_create_input_not_found(self, b, user_pk):
|
||||
from planetmint_cryptoconditions import Ed25519Sha256
|
||||
|
Loading…
x
Reference in New Issue
Block a user