Skip to main content

SQL search and ranking engine in multiple fields of database table

Project description

GitHub GitHub contributors Python package PyPI PyPI - Format GitHub Release Date

SQL_mutlisearch

Easy search engine into SQL tables with results raking and ordering.

Running

Package available on the following databases:

  • sqlite

Installation with

pip install SQL_multisearch

Initialization of the SQL_multisearch class with a simple JSON Body:

from SQL_multisearch import SQL_multisearch

body = {
    "connexion_infos":{...},
    "request": {...},
    "searchable_fields": {...}
}

SQLm = SQL_mutlisearch(body["connexion_infos"], body["request"], body["searchable_fields"])

Available SQL_mutisearch methods

The following methods are available for the SQL_multisearch class:

  • _count(): returns an integer with the number of results
  • _stats(): returns a dictionary with following schema: {'ranks': {'rank_value': count}, 'total': total}
  • _results(): returns a list of results with the following schema: [{'ranking': rank, 'values':{'field_name':'value', ...}}]
  • _columns(): returns a list of the table fields

Database connexion details

The body["connexion_infos"] value is a dictionary of multiple values:

{"connexion_infos":{
    "db_system": "sqlite",
    "db_url": "path to the database or url",
    "db_database": "name of the database",
    "db_table": "table name",
    "db_schema": "schema name"
}}

Authorized request actions

Multiple actions are possible with the body["request"] dictionary. It defines the structure and the caracteristics of the return result:

{"request":{
    "value": "string or integer to search",
    "value_type": "str|int",
    "operande": "like|left_like|right_like|ilike|left_ilike|right_ilike|=|>|>=|<|<=",
    "limit": "get an integer",
    "offset": "get an integer",
    "order": "asc|desc, default=desc",
    "schema":["list of field names to return in the result"]
}}

Ranking and searchable fields

SQL_multiserach gives a rank to each result. The research into the database table is possible into multiples fields. In order to give a different rank for each field, a piority can be indicate in the body. The body["searchable_fields"] allow search in multiple fields with different priorities.

["searchable_fields": [
    {
        "field": "field name",
        "priority": "get an integer"
    },
    ]
]

Exemple

from SQL_multisearch import *

body = {
    "connexion_infos": {
        "db_system": db_type,
        "db_url": db_url,
        "db_database": db_db,
        "db_table": db_table,
        "db_schema": db_schema
    },
    "request":{
        "value": "halles",
        "value_type": "str",
        "operande": "ilike",
        "limit":10,
        "offset":30,
        "order": "asc",
        "schema":["N_inventaire", "Rue", "Nom_site"]
    },
    "searchable_fields": [
        {
            "field": "Rue",
            "priority": 2
        },
        {
            "field": "Nom_site",
            "priority":1
        }
    ]
}

SQLm = SQL_multisearch(body["connexion_infos"], body["request"], body["searchable_fields"])
print(SQLm._count())
print(SQLm._results())
print(SQLm._columns())
print(SQLm._stats())
>>2
>>[{'values': {'N_inventaire': 3898, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 3899, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 3900, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 3901, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 3902, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 3903, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 3905, 'Rue': 'PIERRE LESCOT, RUE', 'Nom_site': 'HALLES_BALTARD'}, 'ranking': 1.4285714285714286}, {'values': {'N_inventaire': 131, 'Rue': 'BERGER, RUE', 'Nom_site': 'LES_HALLES'}, 'ranking': 1.6}, {'values': {'N_inventaire': 132, 'Rue': 'BERGER, RUE', 'Nom_site': 'LES_HALLES'}, 'ranking': 1.6}, {'values': {'N_inventaire': 133, 'Rue': 'BERGER, RUE', 'Nom_site': 'LES_HALLES'}, 'ranking': 1.6}]
>>['N_inventaire', 'Rue', 'N_rue', 'Nom_site', 'Arrondissement', 'Ville', 'Latitude_x', 'Longitude_y', 'Support', 'Couleur', 'Taille', 'Date_prise_vue', 'Photographe', 'Date_construction', 'Architecte', 'Classement_MH', 'Generalite_architecture', 'Mot_cle1', 'Mot_cle2', 'Mot_cle3', 'Mot_cle4', 'Mot_cle5', 'Mot_cle6', 'Cote_base', 'Cote_classement', 'Date_inventaire', 'Auteur']
>>{'ranks': {'1.4285714285714286': 7, '1.6': 3}, 'total': 10}

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

SQL_multisearch-1.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

SQL_multisearch-1.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: SQL_multisearch-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for SQL_multisearch-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a15e60bec75e4e19195580029bd738c3a1ed638eb294e08efedee89774a16d39
MD5 d8e801710b6d0002ef43ae1805f4c690
BLAKE2b-256 f2f8399c5668852c67237611f214ba4d5cc0dd13e2420a2e215bacd059a8dbca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: SQL_multisearch-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for SQL_multisearch-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb5616d0c2ac40a9d0223d61c67fd7469bb944777b463c2d1ab1a632cdcb04fc
MD5 13763d1daea4b353107904c22be9aca0
BLAKE2b-256 a1adb02759e9ee27a6a7affafe94a90c55b9341f2a1f572f1c4da1e54cfbdd53

See more details on using hashes here.

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