Matching mode in coreseek/sphek

Source: Internet
Author: User
The so-called matching pattern is how the user searches for related records in the index database based on keywords.


Sph_match_all: match all query tokens (default mode );
For example, "mobile phone accessories" do not match "I have a mobile phone", but you can match "the mobile phone is broken and you need to find the accessories ".
Because "mobile phone accessories" are divided into "mobile phones" and "accessories", the matching conditions must contain both words, so "I have a mobile phone" does not meet the matching requirements.




Sph_match_any matches any word segmentation in the query term;
For example, "mobile phone accessories" will match "I have a mobile phone", because the index library can be searched as long as it contains any word segmentation. Of course, it can also match "the mobile phone is broken and accessories need to be found ".




Sph_match_phrase, which regards the entire query as a phrase and requires a complete match in order;
This is similar to select * from [Tab] Where key like '% mobile phone accessories %'. For example, if "mobile phone accessories" do not match "The phone is broken, you need to find accessories ", but it can match "Do you have any mobile phone accessories here? ".


Sph_match_boolean: queries are treated as a Boolean expression, which can be a simple and non-operation;
For example (cat! Dog) | (cat! Mouse)
It means to search all the query tokens that match cat but do not match dog and mouse.


Sph_match_extended2: Extended matching mode
Queries are treated as expressions in the internal Query Language of sph?/ coreseek.
You can use the following special operators in the extended query mode:


  • Or (OR) OPERATOR:
Hello | world


  • Non (not) OPERATOR:
Hello-world
Hello! World


  • Field search operator:
@ Title Hello @ body world
# The title field contains the hello body field containing world


  • Field limit Modifier
@ Body [50] Hello
# The maximum number of body digits is 50.


  • Multi-field search operator:
@ (Title, body) Hello World
# The title or body field contains Hello World


  • Full field search operator:
@ * Hello
# As long as one of the columns contains hello


  • Approximate search operator:
"Hello World "~ 10
# Up to 10 words can be entered between Hello World


  • Threshold match:
"The world is a wonderful place"/3
# Match at least three words


  • Strictly ordered search operator (that is, "before" search operator ):
AAA <BBB <ccc
# AAA, BBB, and CCC must appear in sequence

  • Field start and end Modifier

^ Hello... world $
# The limit must start with hello and end with world




For example, "Hello World" @ title "example program "~ 10 @ body Python-(PhP | Perl) @ * Code
Both requirements are required:
Search for adjacent "hello" and "world" in any field of the document"
The title field of the document must also contain "example" and "program", and there are up to 10 (not including 10) other words between them.
At the same time, the body field must contain the word "Python", but neither "php" nor "Perl"
Any field contains "code"




Sph_match_extended, same as sph_match_extended2, to be compatible with earlier versions;




Sph_match_fullscan: forces the "Full scan" mode described below to match the query;

Note: In this mode, all query words are ignored. Although the filter, filter range, and grouping still work, no text match will happen.

Text matching is not performed here. Even if you pass the query word, It will be ignored and used for filtering. For example, I search all restaurants in Beijing in the restaurant index, you only need to use the setfilter method to filter the IDs of Beijing place names.






Set using the setmatchmode function in PHP, for example:
<? PHP
$ SC = new sphinxclient ();
$ SC-> setmatchmode (sph_match_any );

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.