A
A
armo922015-11-08 11:03:30
MySQL
armo92, 2015-11-08 11:03:30

SphinxSearch sort by search parameters?

Good afternoon, I have such a task on the Sphinx

index mc_offers
{
  type			= rt
  
  path			= /var/lib/sphinxsearch/mc_offers
  
  rt_mem_limit		= 16M
  
  rt_field		= 	title
  rt_field		= 	description
  rt_field                =       short_description
  rt_field		= 	tags
  rt_field		= 	sub_section
  rt_field                =       user_residency

  rt_attr_string		= 	title
        rt_attr_string          =       description
  rt_attr_string          =       short_description
  rt_attr_string		= 	tags
  rt_attr_uint		= 	section_id
  rt_attr_string		= 	sub_section
  rt_attr_uint		= 	location_id
  rt_attr_uint		= 	place_id
  rt_attr_uint		= 	price_aed
  rt_attr_uint		= 	price_usd
  rt_attr_string          =       user_residency
  rt_attr_uint		=	label_id
  rt_attr_float		= 	lat
  rt_attr_float		= 	lng

  min_word_len	=	1
  min_infix_len	=	1
  enable_star	=	1
  dict		=	keywords

  charset_type	= utf-8
  
 	charset_table		= 0..9, A..Z->a..z, _, !,  /, +,  a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F,\
 				   U+0531..U+0556->U+0561..U+0586, U+0561..U+0586, U+0587, U+2116,
}

this is the real time index configuration
+------+--------+-------------+------+----------+
| id   | weight | sub_section | id   | weight() |
+------+--------+-------------+------+----------+
|    9 |   2598 | 1 2         |    9 |     2598 |
|   15 |   2598 | 1 2         |   15 |     2598 |
|   31 |   2598 | 1 2 5       |   31 |     2598 |
|   51 |   2598 | 1 2 5       |   51 |     2598 |
|   55 |   2598 | 1 2         |   55 |     2598 |
|   56 |   2598 | 1 2         |   56 |     2598 |
|   57 |   2598 | 1 2         |   57 |     2598 |
|   64 |   2598 | 1 2         |   64 |     2598 |
|   65 |   1543 | 1 5         |   65 |     1543 |
|    1 |   1531 | 1           |    1 |     1531 |
|   29 |   1531 | 1 5         |   29 |     1531 |
|   32 |   1531 | 1 5         |   32 |     1531 |
|   38 |   1531 | 1 3 4       |   38 |     1531 |
|   40 |   1531 | 1 5         |   40 |     1531 |

this is a sample from the index please pay attention to sub_section
I have such a query
SELECT `id`, WEIGHT()  FROM `mc_offers` WHERE MATCH('@sub_section 1|2')  LIMIT 0,10;

The question is, is it possible to sort the result so that from the first there are all those who have 1 in sub_section and then all those who have 2?
Help please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Puma Thailand, 2015-11-08
@opium

Sort on receiver side

E
Eugene, 2016-07-19
@Jekshmek

Or write your own custom sort function to the UDF

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question