Django 1.10 provides full-text search functionality in PostgreSQL

Source: Internet
Author: User
Tags postgresql in python

The Django 1.10 release has been released, and the new features presented in this release include Full-text search of the PostgreSQL database, official support for Unicode username, and new middleware.

As a dynamic language for the Django Software Foundation, this Django major release includes the ability to call database functions in the Django.contrib.postgres.search module, which facilitates the use of the PostgreSQL Full-text search engine.

The Django team gives examples of code that enables a simple search of a row of data in a database. The code looks like this:

>>> Entry.objects.filter (body_text__search= ' Cheese ')
[<entry:cheese on Toast recipes>, <entry:pizza Recipes>]


"Code calls the To_tsvector function once from the Body_text domain of the database and calls the Plainto_tsquery function once for the retrieve word ' Cheese '. These two function calls use the default database retrieval configuration. The search results are obtained by matching the query with the vector. In order to use this retrieval lookup feature, the environment settings Installed_apps must include ' django.contrib.postgres '. ”

In your Django documentation, you can find examples of using Searchvector, SearchQuery, and Searchrank classes, as detailed here.

The new features of the Django 1.10 release also include the introduction of a new type of middleware that solves the problem of "lack of a strict request and response layer in the legacy middleware proposed in DEP 0005 improvements".

As an "architecture for hooking Django request and response processing", the new Django Middleware provides a django.utils.deprecation.MiddlewareMixin module for creating middleware and Middleware_ Classes compatible middleware classes.

As described in the Django document, the mixed-type module provides the __init__ () method, accepts Get_response as an optional parameter, and saves the parameter in Self.get_response. A detailed explanation of this method is as follows:

__call__ () Method:

Call Self.process_request (Request) (if it is already defined);
Call Self.get_response (Request) to get the response from subsequent middleware and views;
Call Self.process_response (Request, response) (if defined);
Returns the response.
There is a lot of certainty about Django's latest news on the web, but some comments suggest a need for a channels project.

In a discussion of "Django 1.10 released" by the Hackernew website, user Tom Forbes commented: "The channels project is a shame, and I found that the new version does not include this project." and the user Ubernostrum reply: "The Channel project will be successful." It's just not ready for release in version 1.10. Hopefully it will be ready in version 1.11 and will be enabled in Django. ”

User Passiveincomelg gave a less-than-certain statement: "I have some contradictions with channel's attitude." On the one hand, it's cool to use what it can do, and its design is smart enough to avoid rewriting all Django programs for Asynchrony. On the other hand, it's maddening to realize how much of this go and Erlang is going to do, and how many pranks to complete. ”

The Django version 1.10 also includes some improvements that are not backwards compatible. There are also some features that have been discarded after they have reached their discard cycles.

These deprecated features include the use of dotted Python paths in login_url and Login_redirect_url; Django.core.context_processors, Modules such as Django.db.models.sql.aggregates and django.contrib.gis.db.models.sql.aggregates; quote_name_ for the use of Sqlcompiler The Unless_alias method supports calling Sqlcompiler directly with aliases and some other proprietary APIs.

As a free open source Web application framework written in Python, Django is released in the three-sentence BSD protocol, and it welcomes the contribution from the INFOQ community.

Anyone who seeks improvement and contributes to Django can access docs.djangoproject.com/en/dev/internals/contributing/.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.