P
P
Pavel Shvedov2014-07-23 12:14:48
Django
Pavel Shvedov, 2014-07-23 12:14:48

How to search Django models for the most property matches?

Hello everyone, I have a question. There is a task - to implement something like a product filter like on Yandex.Market on Django.
I specify:
There is a model class, and accordingly, a lot of records in the database corresponding to this model. On the interface page there will be a form with editing the parameters of this model, the output should be a list of N instances of this model, in which the largest number of matches with the values ​​entered on the page. Sort accordingly by the number of matching properties.
Why am I asking:
The following idea came to mind: take from the database those rows in which there is at least one match with the entered parameters, and programmatically generate that list. But there is one thing, such a request can result in a huge array of objects, and since it is expected that this list will be updated asynchronously on the page, by Ajax, for any change in one of the parameters by the user, a very frequent request for a very large amount of data will turn out, as it were did not affect the speed, and it does not sound extremely optimal.
Has anyone come across this kind of functionality? What algorithms and techniques are used for this. or maybe Django has ready-made tools (even from third-party developers) for solving such problems?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Solovyov, 2014-07-23
@pavel_salauyou

there is such a topic paging and it is not necessary to display all objects at once

A
Alexander, 2014-07-23
@syschel

I'm dealing with a similar issue right now.
I have implemented three models
1. Product
2. Feature name
3. Feature value
3.1. Communication with the goods
3.2. Relationship with the name of the characteristic
3.3. Characteristic value The
search is based on the third model. There are a lot of records, according to the number of lines. But little data is stored in them.
The first request - we get 3.3, we get the selected number of goods. The second request for the ID of the goods from this list pulls out the goods themselves.
There is also an option to use search engines, rather than force the database to search.

R
Roman, 2014-07-31
@romamo

Sphinx https://github.com/Yuego/django-sphinx
Memcached for caching counters and fetch results

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question