eb0t
eb0t

Reputation: 127

How to search django Postgres table textarea field for multiple words?

I am creating a recruitment website, and i need to search a keys skills text area field, for multiple values.

eg. I may be looking for a C++ programmer with good python, and worked in healthcare data scientist.

so my search entry form i would put c++ python healthcare data scientist.

there could be up to 20 staff performing searches against a database with a few thousand records. I need to know what is the best technology to perform this type of search with Django and postresql database hosted on digitalocean.

Upvotes: 1

Views: 483

Answers (2)

Paolo Melchiorre
Paolo Melchiorre

Reputation: 6122

I can suggest to use Django with PostgreSQL Full-Text Search.

In my opinion it's the best solution because you will have the data and the search indexes directly inside PostgreSQL and you will not be forced to install and maintain additional software (such as Elasticsearch) and keep the data and indexes in sync.

This is the simplest code example you can have to perform a full-text search in Django with PostgreSQL:

search_entry = 'c++ python healthcare data scientist'
Person.objects.filter(skills__search=search_entry)

For all the basic documentation on using the full-text search in Django with PostgreSQL you can use the official documentation: "Full text search"

If you want to deepen further you can read an article that I wrote on the subject:

"Full-Text Search in Django with PostgreSQL"

Upvotes: 1

eatmeimadanish
eatmeimadanish

Reputation: 3907

You should look into using the JSONB storage in postgres. Which is NOSQL inside a SQL database.

https://www.postgresql.org/docs/9.6/static/functions-json.html

How to access in DJANGO https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#querying-jsonfield

Upvotes: 0

Related Questions