damoti / django-tsvector-field Goto Github PK
View Code? Open in Web Editor NEWDjango field for tsvector (PostgreSQL full text search vector) with managed stored procedure and triggers.
License: BSD 3-Clause "New" or "Revised" License
Django field for tsvector (PostgreSQL full text search vector) with managed stored procedure and triggers.
License: BSD 3-Clause "New" or "Revised" License
Pending readonly
field attribute implementation in Django:
fields.py
imports django.utils.encoding.force_text
which has been deprecated in favor of force_str
. Django 4.0 has now removed the function entirely: https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0
Any chance for a simple update on this really handy package so I can keep using it with the latest django versions?
Following along with the tutorial I've added a 'search' field to an existing model and generated the migration file. But when I run 'migrate' the migrations fails with a ProgrammingError 'name-of-the-field_tsvector' already exists.
Running django-tsvector-field 0.9.3, django 1.11, and PostgreSQL 9.5.6
Hey, awesome library! I was disappointed to see that Django does not offer any support out of the box for FTS for real applications - using triggers and store procedures instead of indexing on the fly - which obviously does not scale on even a modest level of traffic.
For our use case, we'd like to index fields on related models through joins. One simple example to allude to is the ability to search for orders by line item descriptions. Briefly digging into the codebase, it does not look like this is currently supported.
I'd be happy to contribute something to make this work. Has this feature been thought about before? Any recommendations for how this should be tackled?
I believe there is a bug in the generated trigger logic. If a NULL column is given a non-NULL value, this won't trigger an update to the tsvector field to include the new text.
The issue is with logic like:
ELSIF (NEW."some_indexed_field" <> OLD."some_indexed_field") THEN do_update = true;
Since NULL <> 'something'
is not true in SQL. The simplest solution I could come up with is to replace the <>
tests with IS DISTINCT FROM
.
Let me know if you'd like a pull request.
Update the README with some instructions on how to use the Headline
class and present matched excerpts from the result set....
https://github.com/damoti/django-tsvector-field/blob/master/tsvector_field/query.py#L5
from django.db.models.expressions import F
from django.contrib.postgres.search import SearchRank, SearchQuery
import tsvector_field
query = SearchQuery(self.form['text'].value())
qs = (
qs.filter(text__search=query)
.annotate(
match_title=tsvector_field.Headline(F('text__title'), query),
match_text=tsvector_field.Headline(F('text__text'), query)
)
.annotate(rank=SearchRank(F('text__search'), query))
.order_by('-rank')
)
The contents of the tsvector
is an implementation detail in postgres, it's kind of pointless to keep shuttling this back and forth between Postgres and Django.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.