django-haystack / django-haystack/django-haystack

Define indexing constraints only once

Open
#782 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs review
Dominant language
Python
Stars
3.7k
Forks
1.3k
Avg merge
3h 18m
Merged PRs (30d)
3

Description

This is just an idea without any work behind it, but I think it would be nice for keeping things more DRY.

If I'm not wrong, currently when you have a constraint for deciding whether an object should be indexed or not, you need to define this in two places. Imagine you have a boolean field in your model called 'visible'. Visible fields should go to the index, invisible ones should not. You would need to define this in two places:

  1. An index_queryset() method at your SearchIndex class, for when the entire index is rebuilt: Model.objects.filter(visible=True)
  2. The handle_save() method of your SignalProcessor, for when an individual instance is saved, so in case it becomes invisible, you call index.remove_object rather than index.update_object.

It would be nice if there was a way of defining 'constraints' for whether model objects should get indexed or not, in a more generic way, and then haystack pre-building the queryset with these constraints and also checking them when updating an individual instance.

I haven't thought much about it, but I leave the idea here in case you find it interesting. Also, I'm not very familiarized with Haystack yet, so please let me know if I'm just completely wrong and it's already possible to achieve the same in some other way I'm not aware of!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the index_queryset() method on SearchIndex and the handle_save() method on SignalProcessor, which the issue identifies as the two places where indexing constraints are defined. Determine whether a shared constraint mechanism can cover both full index rebuilds and individual saves; done would mean the issue's duplicated constraint example no longer needs separate definitions.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.