Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working through update implementation with Chicago councilmatic #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions postgres_fts_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,38 @@
SearchNode,
log_query,
)
from haystack.constants import DEFAULT_ALIAS
from haystack.constants import DEFAULT_ALIAS, ID
from haystack.exceptions import SkipDocument
from haystack.inputs import Clean, PythonData
from haystack.models import SearchResult
from haystack.utils import get_model_ct_tuple


class PostgresFTSSearchBackend(BaseSearchBackend):
def update(self, indexer, iterable, commit=True):
warn("update is not implemented in this backend")
def update(self, index, iterable, commit=True):
prepped_docs = []

for obj in iterable[0:10]:
try:
print(obj)
prepped_data = index.full_prepare(obj)
prepped_data["_id"] = prepped_data[ID]
prepped_docs.append(prepped_data)
except SkipDocument:
self.log.debug("Indexing for object `%s` skipped", obj)

print("objects prepped")
from chicago.models import SearchBill, ChicagoBill

prepped_models = []
for d in prepped_docs:
chicago_bill = ChicagoBill.objects.get(id=d['django_id'])
search_bill = SearchBill(text=d['text'], bill=chicago_bill, extras={'django_ct': d['django_ct'], 'django_id': d['django_id']})
prepped_models.append(search_bill)

SearchBill.objects.bulk_create(prepped_models)
print("success")


def remove(self, obj, commit=True):
warn("remove is not implemented in this backend")
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ build-backend = "setuptools.build_meta"
name = "postgres-fts-backend"
version = "0.0.0"
dependencies = [
'django>=5.0',
'django-haystack>=2.8.0',
]
requires-python = ">= 3.8"
requires-python = ">= 3.7"
authors = [{name = "Forest Gregg", email = "[email protected]" }]
description = "A PostgreSQL Full Text Seach Backend for Haystack"
readme = "README.md"
Expand Down