Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 992003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:11:50+00:00 2026-05-16T06:11:50+00:00

I was following the documentation on FullTextSearch in postgresql. I’ve created a tsvector column

  • 0

I was following the documentation on FullTextSearch in postgresql. I’ve created a tsvector column and added the information i needed, and finally i’ve created an index.
Now, to do the search i have to execute a query like this

SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank
FROM client, plainto_tsquery('famille age') query
WHERE textsearchable_index_col @@ query
ORDER BY rank DESC LIMIT 10;

I want to be able to execute this with Django’s ORM so i could get the objects. (A little question here: do i need to add the tsvector column to my model?)
My guess is that i should use extra() to change the "where" and "tables" in the queryset

Maybe if i change the query to this, it would be easier:

SELECT * FROM client
WHERE plainto_tsquery('famille age') @@ textsearchable_index_col
ORDER BY ts_rank_cd(textsearchable_index_col, plainto_tsquery(text_search)) DESC LIMIT 10

so id’ have to do something like:

Client.objects.???.extra(where=[???])

Thxs for your help 🙂
Another thing, i’m using Django 1.1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:11:51+00:00Added an answer on May 16, 2026 at 6:11 am

    Caveat: I’m writing this on a wobbly train, with a headcold, but this should do the trick:

    where_statement = """plainto_tsquery('%s') @@ textsearchable_index_col 
                         ORDER BY ts_rank_cd(textsearchable_index_col, 
                                             plainto_tsquery(%s)) 
                         DESC LIMIT 10"""
    
    qs = Client.objects.extra(where=[where_statement], 
                              params=['famille age', 'famille age'])
    

    If you were on Django 1.2 you could just call:

    Client.objects.raw("""
    SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank
    FROM client, plainto_tsquery('famille age') query
    WHERE textsearchable_index_col @@ query
    ORDER BY rank DESC LIMIT 10;""")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed the following documentation and I am having problems. I access the
Following MongoDB documentation example seems to be wrong. Any suggestion? a== 1 and a
Following the documentation, I am able to display the person object in the sayHelloView
I've been following the documentation at the resource below http://silex.sensiolabs.org/doc/providers/form.html But I get the
I'm following the documentation with an up to date automake (v1.12) but building still
I'm following the documentation here as I would like to add Actors to the
I have set up the OAuth request following the documentation for a Non-Google Service
By using the following tool oAuth Playground , and following the documentation Google Documents
I'm trying to use System.Data.Sqlite library, and I'm following the documentation about optimizing inserts
I'm trying to implement my first Spring MVC controller, following Spring documentation, some tutorials

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.