Skip to main content

Algolia Query Builder

Project description

A library to help build queries for searching Algolia.

This package is meant to be used with the algoliasearch library.

PyPI version

Problem:

An app I have been working on has a few points of code duplication and increased complexity. This package is a way for me to fix those issues and increase readability.

Installation

pip install algoliaqb

Filter Strings

By default filter_map considers all input as strings. This is pretty straight forward. Lets say for example you have the following filter map:

filter_map = {
    "group_id": "tenant_id",
}

with the following flask.args:

{
    "group_id": 1
}

AlgoliaQB will look for group_id within flask.args, grab the value, then remap the key and value for you.

tenant_id:1

Now lets try an example with a few more filters.

filter_map = {
    "group_id": "tenant_id",
    "is_reported": "is_reported"
}

with the following flask.args:

{
    "group_id": 1,
    "is_reported": "true
}

The returned filter_string is as follows.

tenant_id:1 AND is_reported:true

Library Usage Example:

from algoliasearch.search_client import SearchClient
from algoliaqb import AlgoliaQueryBuilder
from flask import request


aqb = AlgoliaQueryBuilder(
    search_param="search",
    filter_map={
        "group_id": "tenant_id",
        "is_reported": "is_reported"
    }
)

# Extract the search query from our flask apps request.args var.
search_query = aqb.get_search_query(request.args)
# Get the filter query from our request args.
filter_query = aqb.get_filter_query(request.args)

# Now that we have the filter string, we just pass it into the search function.

search_client = SearchClient()
index = search_client.init_index("contacts")
results = index.search(search_query, {"filters": filter_query})

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

algoliaqb-0.0.8.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

algoliaqb-0.0.8-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file algoliaqb-0.0.8.tar.gz.

File metadata

  • Download URL: algoliaqb-0.0.8.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for algoliaqb-0.0.8.tar.gz
Algorithm Hash digest
SHA256 253a3b46a1b18bb7f9c4ba011125f589c221821a700baa44b6da03fdb86378fb
MD5 66264d7ea91e940b0823a30f3975513a
BLAKE2b-256 b1180c2f949fd6bbd4e222a6301465a2f587b49e694c1d85a0b1b8ff968db055

See more details on using hashes here.

File details

Details for the file algoliaqb-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: algoliaqb-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for algoliaqb-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ed78c59009a5cc91f157490a07034b3b0dd6d54a42246c41b696d3d53b752f2f
MD5 77d5866f9ae8d0489a2d433dbf54abae
BLAKE2b-256 0c678dfb618697e73280f09b3129b94990ed9ea683cbe385ecd35828e5b5cff1

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