Filtering Django-sphinx results using attributes?

I went through the django-sphinx documentation , and it looks like it allows you to filter search results using attributes,

queryset = MyModel.search.query('query')
results1 = queryset.order_by('@weight', '@id', 'my_attribute')
results2 = queryset.filter(my_attribute=5)
results3 = queryset.filter(my_other_attribute=[5, 3,4])
results4 = queryset.exclude(my_attribute=5)[0:10]

In some examples, these attributes are apparently what you specify in the sphinx configuration file, and are not the actual values ​​of the column in the table. The configuration file allows something like this,

# ForeignKey's
# Apparently sql_group_column is now replaced by sql_attr_uint
sql_group_column    = country_id
sql_group_column    = state_id
sql_group_column    = listings

# DateField and DateTimeField's
sql_date_column     = date_added

But it turns out that you can specify Foreign keys as this value. As shown in another example ,

Class City(models.Model):
    ...
    # Comment: The below should probly be country_id and state_id
    country_id      = models.ForeignKey(Country)
    state_id        = models.ForeignKey(State, blank=True, null=True)
    listings        = models.PositiveIntegerField(editable=False, default=0)

When the search result is printed, you get

print results[0]._sphinx
{'id': u'5246', 'weight': 200, 'attrs': {'state_id': 3, 'country_id': 0}}

As you can see, in attrs - state_id and country_id - being FK, are displayed. But lists do not.

. sphinx, aribtrary column foo - ?

!


,

sql_attr_uint, sql_group_column .. , , Django Sphinx (, ) _Sphinx dict if FK.. (. " " ). , SQL_Query.. .. (, *)

+3
1

, , django-sphinx, . , , , sphinx , , .

sphinx.conf:

sql_query_pre       =
sql_query_post      =
sql_query           = SELECT `id`, `content_type_id`, `site_id`, `user_id`, `title`, `abstract`, `summary`, `fulltext`, `approved` FROM `basedoc`
sql_query_info      = SELECT * FROM `basedoc` WHERE `id` = $id

sql_attr_uint    = content_type_id
sql_attr_uint    = site_id
sql_attr_uint    = user_id
sql_attr_uint    = approved

, non-fk () django. , : sql_attr_uint sql_group_column sql_query.

+1

Source: https://habr.com/ru/post/1712729/


All Articles