Sphinx Sort Mode Setsortmode

Source: Internet
Author: User

Search results can be sorted using the following pattern:

    • Sph_sort_relevance mode, sorted in descending order of relevance (best match in front)
    • Sph_sort_attr_desc mode, arranged in descending order of attributes (the higher the value of the property, the greater the number of rows in front)
    • SPH_SORT_ATTR_ASC mode, arranged in ascending order of attributes (the smaller the attribute value, the more it is in front)
    • Sph_sort_time_segments mode, descending by time period (last hour/day/week/month), and then by relevance
    • sph_sort_extended mode, which combines columns in ascending or descending order in a SQL-like way.
    • sph_sort_expr mode, sorted by an arithmetic expression.

Sph_sort_relevance ignores any additional parameters and is always sorted by relevance rating. All the remaining patterns require an additional sort clause, and the syntax of the clause is related to the specific pattern. SPH_SORT_ATTR_ASC, Sph_sort_attr_desc, and sph_sort_time_segments require only one property name for each of the three modes. The sph_sort_relevance mode is equivalent to the "@weight DESC, @id ASC" sort in extended mode, SPH_SORT_ATTR_ASC mode is equivalent to "attribute ASC, @weight DESC, @id ASC", And Sph_sort_attr_desc is equivalent to "attribute desc, @weight desc, @id ASC".

Sph_sort_time_segments mode

In sph_sort_time_segments mode, attribute values are split into "time periods," then sorted by time period and then by relevance.

The time period is calculated based on the current timestamp when the search occurred, so the results change over time.

The time period of the division Cure in the search program, but if necessary, it can be relatively easy to change (need to modify the source code).

This model is designed to facilitate the search for blog logs and news feeds, and more. When you use this pattern, records that are in a more recent time period are in front, but the records in the same time period are sorted by relevance-this differs from simply sorting by timestamp regardless of relevance.

sph_sort_extended mode

In sph_sort_extended mode, you can specify an SQL-like sort expression, but the properties involved (including internal properties) cannot exceed 5, for example:

@relevance desc, price ASC, @id desc

As long as the relevant settings are made, both the internal properties (those that are computed dynamically by the engine) or the user-defined properties are available. The name of the internal attribute must begin with the special symbol @, and the user attribute is used as is. In the example above, @relevance and @id are internal properties, and price is a user-defined attribute.

Known built-in properties:

    1. @id (ID of the matching document)
    2. @weight (matching weights)
    3. @rank (equivalent to weight)
    4. @relevance (equivalent to weight)
    5. @random (return results in random order)

@rank and @relevance are just @weight aliases.

sph_sort_expr mode

The expression sort pattern allows you to sort matches by any arithmetic expression, and the items in the expression can be attribute values, internal properties (@id and @weight), arithmetic operators, and some built-in functions. For example:

$cl->setsortmode (sph_sort_expr,

"@weight + (User_karma + ln (pageviews)) *0.1");

The following operators and functions are supported. They are designed to mimic MySQL. The function accepts parameters, and the number of arguments differs depending on the specific function.

    1. Operators: +,-, *,/, <, > <=, >=, =, <>.
    2. Boolean operator: And, OR, not.
    3. No parameter function: Now ().
    4. unary function (one parameter): ABS (), ceil (), Floor (), SIN (), COS (), LN (), LOG2 (), LOG10 (), EXP (), SQRT (), BIGINT ().
    5. A binary function (two parameters): MIN (), MAX (), POW (), Idiv ().
    6. Other functions: IF (), INTERVAL (), in (), Geodist ().
Reference Sources
    • Http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html#required-tools
    • Http://blog.sina.com.cn/s/blog_998c494301016t35.html

Sphinx Sort Mode Setsortmode

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.