Inaccurate full-text search in PostgreSQL and Django

I'm new to PostgreSQL, and I'm not sure how to make full-text search inaccurate . Not that it's too important, but I'm using Django. In other words, I'm looking for something like the following:

q = 'hello world'
queryset = Entry.objects.extra(
    where=['body_tsv @@ plainto_tsquery(%s)'], 
    params=[q])
for entry in queryset:
    print entry.title

where I list of entries should contain either "hello world" or something like that. Then the lists should be ordered according to how far their value is indicated on the indicated line. For example, I would like the query to include entries containing "Hello World", "hEllo world", "helloworld", "hell world", etc., with some kind of ranking indicating how far from each element is perfect, unchanging query string.

How would you do that?

+5
source share
2 answers

It is best to use Django raw querysets , I use it with MySQL to fully match the text. If all the data is in the database, and Postgres provides the ability to map, then it makes sense to use it. Plus Postgres offers some really useful things in terms of sterilization, etc. With full text queries.

This basically allows you to write the actual query you want, but returns the models (while you are explicitly viewing the model table).

, , , , Postgres, .

- . , , - .


, , . postgres fuzzystrmatch contrib. .

+2
+1

All Articles