I have a list of posts with a title and descrption. I have found the full text search documentation for postgres database here. But this is not useful for me as I am presently using sqlite3 database.
What are my options to have a similar functionality for my sqlite3 db?
Since full-text-search is a database(PgSQL) specific tool, Django doesn't natively support for full text search in sqlite database,
Read more on Searching in other databases
All of the searching tools provided by django.contrib.postgres are constructed entirely on public APIs such as custom lookups and database functions. Depending on your database, you should be able to construct queries to allow similar APIs. If there are specific things which cannot be achieved this way, please open a ticket.
More: https://docs.djangoproject.com/en/2.0/topics/db/search/#a-database-s-more-advanced-comparison-functions
Related
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.
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"
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
I'm making a django project where there is the need to use information from an ApiRest. To manage the information more easily I created classes to get the info and display it.
Since my classes aren't django models the relashionships between those and my database take a lot of work and will break with each change I make. So I want to use a custom database backend instead of the classes. But there I cant find any documentation on how it should be done.
Is there a place where I can find the documentation of how a database engine works in django?
I have already looked in the django docs but there is no article or section about database engines. Or I couldn't find it.
edit: added info
I'm looking to do something similar - Creating a custom database engine using pyodbc.
I found
https://www.youtube.com/watch?v=tkwZ1jG3XgA
https://simpleisbetterthancomplex.com/media/2016/11/db.pdf and
https://reinout.vanrees.org/weblog/2016/11/04/database-backends.html
as good documentation starting points.
Then I created https://pypi.org/project/django-filemaker-pyodbc/0.0.1/ after going through the documentation and reading through django_pyodbc
I'm in the process of choosing a Framework for a new project. I have basically the database schema developed(I have this schema running in other PHP webapps already).
In this project I will need to basically search the database schema with Solr. The database schema is a little bit complex to define models in Django, so I think the only option I have is to execute SQL directly... my doubt is about Haystack/Solr... It is possible to query Haystack/Solr when I have no Django Models defined?
PS: I'm new to Django, I have never userd Haystack.
Haystack is pretty tightly coupled to the Django ORM. If you're not using Django models, I don't think Haystack is suitable. I've only used Haystack briefly, so I might wrong.
From the Haystack docs:
When should I not be using Haystack?
Non-Model-based data. If you just want to index random data (flat files, alternate sources, etc.), Haystack isn’t a good solution. Haystack is very Model-based and doesn’t work well outside of that use case.
I never used haystack, but you can always perform raw sql queries.
Have a look on documentation:
https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly
For a project I implemented Haystack but now I was wondering what the pros and cons are of using Haystack over the ORM. For my project I need to find books by their title and isbn. I guess Haystack is more useful if you have to do full text searches or am I missing something?
Haystack is certainly better for full text search, and also provides a bunch of other benefits that you won't get using the ORM. Here are some from the Haystack site:
Spelling suggestions
Faceting
More like this
Highlighting
Search term boosting
Besides that, you should use Haystack over the ORM if you expect a high volume of searches, since you'll offload all that work from the DB (which should be focused on writing and retrieving your data).
http://haystacksearch.org/
The main advantage to use haystack over the ORM is performance. LIKE requests are just going to kill you database if you have 100 concurrent users searching. If you have MYSQL of course you can still use its full text capability, but it will still be slower than Xapian or Solr.
Plus you will have additional features such as fuzzy searching that user loves a lot.
It does comes with the extra work of setting up solr and maintaining it, so:
if your website is going to be small forever, like for small company intranet, don't bother and user ORM.
if you plan for the big bad Web, go Haystack.
And not forget to mention that doing a basic haystack setup isn't really much more work than doing a search view using Django's ORM.
Haystack is a module that enables easier search integrations for your django application
you can create something similiar to a ModelForm, called ModelIndex, in this new class you will be able to declare the searchable fields of your models and other settings
It has little to do with Django ORM (the orm is used to comunicate with your databases)
of course you can have the orm query your db models with the search pattern specified, but Haystack is a better choice for setting up a search engine easily on your website, so... if you have to enable complex searches on your site, just go with Haystack
I am building a web interface for a database at my school. The database will hold our school's versions of academic standards.
When you build a site using django, does it create a clean database? For example, wysiwyg website builders like dreamweaver create ugly html and css code on the backend. I would hate to see a similar degree of auto-generated cruft in my database.
Should I create the database myself and then build a django site to access the database, or go ahead and let django create the database?
Under any simple to moderately complex application, Django will do a fine job creating the database for you. I've yet to run into any issues with what it's made.
I would suggest that you use South to handle your table migrations. And use virtualenv and pip to set up and maintain your Django environment.
You can use the sqlall predicate of manage.py to see the exact SQL that will be executed in order to generate the database.
Obviously django needs database tables for its basic functionality (contrib.apps).
Sure, you don't have to use them, but generally you want to use a least contrib.auth and some other bundled apps:
Each of these applications makes use
of at least one database table,
though, so we need to create the
tables in the database before we can
use them.
I any case you can't and shouldn't compare it to ugly html code generated by dreamweaver or word.
On a more abstract level:
One of key concepts of a web framework (following the mvc pattern) is that you define models which are "translated" (mapped) by the framework into database tables.
A model is the single, definitive
source of data about your data. It
contains the essential fields and
behaviors of the data you’re storing.
Generally, each model maps to a single
database table.
If you want to create the whole database scheme by hand you totally missed the point of using a web framework. In most cases you simply don't need to write sql manually. You define your classes and then you can query your objects using the builtin orm.