Sphinx keyword Set broken

Source: Internet
Author: User

Sphinx Define search results, the content of the search is highlighted, you can use the following code

1<?PHP2 /**3 * Created by Phpstorm.4 * user:pc000015 * DATE:2015/4/106 * time:14:187  */8 Header(' Content-type:text/html;charset=utf-8 ');9 include_once(' sphinxapi.php ');Ten  One $sp=Newsphinxclient (); A  - $sp->setserver (' 127.0.0.1 ', 9312);//Server Connection - $sp->setconnecttimeout (5);//Timeout period the $sp->setlimits (0,10);//number of strips removed -  - $keywords=isset($_request[' KY ']?$_request[' KY ']: ' New '; -  + $res=$sp->query ($keywords,‘*‘); -  +  A $res _id= (implode(‘,‘,Array_keys($res[' Matches ']))); at  - $conn=mysql_connect(' 127.0.0.1 ', ' root ', '); - mysql_query(' Set names UTF8 '); - mysql_query(' Use Ldds '); - $sql= "Select*from ld_goods where goods_id in ($res _id)"; - $tmp=mysql_query($sql,$conn); in  - $query _res=Array(); to  while($row=Mysql_fetch_assoc($tmp)){ +     $query _res[] =$row; - } the  *  $ $goods _name=Array();Panax Notoginseng $res=Array(); - //Define keyword Callout content the $build _opts=Array( +' Before_match ' = ' <font color= ' red ' > ',//HTML that was added before the keyword A' After_match ' = ' </font> '//HTML added after a keyword the ); +  -  $ foreach($query _res  as $k=$v){ $     $goods _name[$k] =$v[' Goods_name ']; - } -  the //parameters are (the content to be labeled, index name, keyword, definition of the keyword set array) - $res=$sp-Buildexcerpts ($goods _name, ' MySQL ',$keywords,$build _opts);Wuyi Print_r($res); the //var_dump ($goods _name); exit;

The results appear similar to the following:

[0] = 2014 spring new female embroidery knit cardigan jacket floating Sang blue [1] = 2014 spring new female embroidery sweater cardigan coat floating Sang Green

Other common methods

Common methods in other SPHINXAPI 1$sp-Setmatchmode (); Sph_match_all,Match all query terms (default mode) Sph_match_any,match any one of the sph_match_phrase in the query word,treat the entire query as a phrase that requires a complete match in order Sph_match_boolean,treat a query as a Boolean expression (a search that does not contain keywords) sph_match_extended,treat a query as an expression of Sphinx internal Query Language$sp->setfilterrange ($attribute,$min,$max,$exclude=false ); Add a new integer range filter$sp->setfilterrange (' Dateline ', Time()-3600, Time());//querying a time period      $sp->setfilter ($attribute,$values,$exclude=false);//Query the specified field as value, as checked by UIDadds an integer value filter. $sp->setsortmode ($mode,$sortby=""); To set the sorting mode for a match,6 modes sph_sort_expr mode, sorted by an arithmetic expression. $uptime= Time()-60*60*24*60; $sp->setsortmode (sph_sort_expr, "@weight + IF (Dateline >$uptime, 1,0) ")

$SP->setfieldweights ($weights);//Set the weight of a field by field name

if (! $is _bytitle) {

$weight = Array (

' title ' and ' content ' = 100,

);

} else {

$weight = Array (

' title ' = +, ' content ' = 10,

);

}

$SP->setfieldweights ($weights); For search by title, or search by content

$sp->setfilterfloatrange ($attribute, $min, $max, $exclude =false);

Add a new floating-point range filter. Use method similar to integer filter

Note: Using these methods, you need to add the contents of the field that contains the data to the index. As in the configuration file:

Sql_attr_uint = Click

Sql_attr_timestamp = Dateline

In addition, these methods must be executed before the query () method executes.

Sphinx keyword Set broken

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.