Skip to main content

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})

Release files for algoliaqb 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for algoliaqb 0.0.9
File Size Uploaded
algoliaqb-0.0.9.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for algoliaqb 0.0.9
File Interpreter ABI Platform
algoliaqb-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / algoliaqb-0.0.9.tar.gz

Download URL algoliaqb-0.0.9.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
97801be7ba8d9b5516598d264539caf087ba9816f70af62ed23d24b835660130
BLAKE2b-256 checksum
How to use checksums
a58515afee9ffc10763cd0302a0523ee0386fbad4bd60c88ec2c794556d64e04
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / algoliaqb-0.0.9-py3-none-any.whl

Download URL algoliaqb-0.0.9-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83502e6f35318421b8e116dc018e852cb91af57fffb75c9646a59be6180faa5e
BLAKE2b-256 checksum
How to use checksums
5f56faa0d6a3a5b904b1a8dec0b8f5e35ca65cf356c9139bd1d7235b7b219964
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

0.1

2 release files

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page