Skip to main content

Maintainability Maintainability Test Coverage image image

Postgresql search handler for Django-Oscar

This creates a search handler without the need of any search backend. It is designed for the e-commerce framework Oscar.

It is implemented a little bit expensive but uses 4 annotated search vectors: * upc * title * meta_description * meta_title

This way the search can be manipulated through the meta fields. It is running productive in a heavily customized env for many months now. I think it should scale up to 5000 Products with 10 Attributes depending on how the products are loaded. We use it fully lazy with endless scrolling.

To-Do

  • Provide a generic way to use filter forms
  • Writing Tests

Features

  • Don't need to use some additional search backend like elastic
  • Creates filters (facets) for:
    • Data that is directly attached to the Product model
    • including foreign key choices
    • AttributeValues of the products
    • StockRecord entries

Installation

Basic

Install using pip:

pip install django-oscar-pg-search
# settings.py

# replace 'oscar.apps.search.apps.SearchConfig' by 'oscar_pg_search.apps.PgSearchConfig'
INSTALLED_APPS = [
	# 'oscar.apps.search.apps.SearchConfig',
    'oscar_pg_search.apps.PgSearchConfig',
]

OSCAR_PRODUCT_SEARCH_HANDLER = 'oscar_pg_search.postgres_search_handler.PostgresSearchHandler'

# To avoid exception, haystack is not used:
HAYSTACK_CONNECTIONS = {"default": {}}

Trigram search is our search algorithm. Enable it at your database by executing the following sql:

CREATE EXTENSION pg_trgm;

Optional Search box

To install the included Search box that passes the previous search term. (eg. in 'oscar/partials/search.html')

{% include 'oscar_pg_search/partials/search.html' %}

Optional Filter Forms

To use the included filter forms, include them in the template eg. in 'oscar/layout_2_col.html' after '{% block column_left_extra %}{% endblock %}'.

{% include 'oscar_pg_search/catalogue/partials/filter_forms.html' %}

and include the mixin into the catalogue views.

# apps/catalogue/views.py
from oscar.apps.catalogue import views
from oscar_pg_search.mixins import SearchViewMixin


class CatalogueView(SearchViewMixin, views.CatalogueView):
    pass


class ProductCategoryView(SearchViewMixin, views.ProductCategoryView):
    pass

Optional Use Chosen.js

To empower multiple choice fields with chosen load it eg. in 'oscar/base.html'.

# At the beginning:
{% load oscar_pg_search %}

# After jQuery is loaded:
{% oscar_pg_search_base %}

Settings

If you want to add some fields that are directly attached to the Product model:

# settings.py
OSCAR_ATTACHED_PRODUCT_FIELDS = ['is_public', 'deposit', 'volume', 'weight',]

Release files for django-oscar-pg-search 0.9.10

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

Source distribution (sdist)

Source distribution for django-oscar-pg-search 0.9.10
File Size Uploaded
django-oscar-pg-search-0.9.10.tar.gz 28.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-oscar-pg-search 0.9.10
File Interpreter ABI Platform
django_oscar_pg_search-0.9.10-py3-none-any.whl Python 3 none any Details

Total release size: 61.5 kB

Release files / django-oscar-pg-search-0.9.10.tar.gz

Download URL django-oscar-pg-search-0.9.10.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
59317b1a6c69ce428af999982c15ddc6f757d9f95c602861f1de994c16fb3a70
BLAKE2b-256 checksum
How to use checksums
6543bca90a10b2c801d3b83e6a3cb63e73e178d509d305b50d2c16bcca096ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / django_oscar_pg_search-0.9.10-py3-none-any.whl

Download URL django_oscar_pg_search-0.9.10-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f1703b462ae5df7a40077040fac0aaef6022ef3bc184e3259c3a057533e710e
BLAKE2b-256 checksum
How to use checksums
40c8c4d1ecb66aa02d1e517af4fa868fd38110643091e3f266f1868a1594d4ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.9.10 This release

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.14

2 release files

0.8.13

2 release files

0.8.12

2 release files

0.8.11

2 release files

0.8.10

2 release files

0.8.9

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

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