protected function resetClient() { $this->sphinxClient->ResetFilters(); $this->sphinxClient->ResetGroupBy(); $this->sphinxClient->ResetOverrides(); $this->sphinxClient->SetLimits(0, 20); $this->sphinxClient->SetArrayResult(true); $this->sphinxClient->SetFieldWeights(array()); $this->sphinxClient->SetIDRange(0, 0); $this->sphinxClient->SetIndexWeights(array()); $this->sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2); $this->sphinxClient->SetRankingMode(SPH_RANK_NONE); $this->sphinxClient->SetSortMode(SPH_SORT_RELEVANCE, ""); $this->sphinxClient->SetSelect("*"); }
fwrite($file, $client->_reqs[$client->AddQuery("test ")]); fclose($file); $client->SetWeights(array()); // anchor $client->SetGeoAnchor("latitude", "longitude", 10.0, 95.0); $file = fopen("spec/fixtures/data/anchor.bin", "w"); fwrite($file, $client->_reqs[$client->AddQuery("test ")]); fclose($file); $client->ResetFilters(); // rank_mode $client->SetRankingMode(SPH_RANK_WORDCOUNT); $file = fopen("spec/fixtures/data/rank_mode.bin", "w"); fwrite($file, $client->_reqs[$client->AddQuery("test ")]); fclose($file); $client->SetRankingMode(SPH_RANK_PROXIMITY_BM25); // index_weights $client->SetIndexWeights(array("people" => 101)); $file = fopen("spec/fixtures/data/index_weights.bin", "w"); fwrite($file, $client->_reqs[$client->AddQuery("test ")]); fclose($file); $client->SetIndexWeights(array()); // index_weights $client->SetFieldWeights(array("city" => 101)); $file = fopen("spec/fixtures/data/field_weights.bin", "w"); fwrite($file, $client->_reqs[$client->AddQuery("test ")]); fclose($file); $client->SetFieldWeights(array()); // update_simple $file = fopen("spec/fixtures/data/update_simple.bin", "w"); fwrite($file, $client->UpdateAttributes("people", array("birthday"), array(1 => array(191163600)))); fclose($file);
<?php require "spec/fixtures/sphinxapi.php"; $cl = new SphinxClient(); $cl->SetIndexWeights(array('index1' => 10, 'index2' => 20)); $cl->Query('query');
/** * @return SphinxClient: ready to run or false if term is empty */ function prepareSphinxClient( &$term ) { global $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby, $wgSphinxSearch_host, $wgSphinxSearch_port, $wgSphinxSearch_index_weights, $wgSphinxSearch_mode, $wgSphinxSearch_maxmatches, $wgSphinxSearch_cutoff, $wgSphinxSearch_weights; // don't do anything for blank searches if ( trim( $term ) === '' ) { return false; } wfRunHooks( 'SphinxSearchBeforeResults', array( &$term, &$this->offset, &$this->namespaces, &$this->categories, &$this->exc_categories ) ); $cl = new SphinxClient(); $cl->SetServer( $wgSphinxSearch_host, $wgSphinxSearch_port ); if ( $wgSphinxSearch_weights && count( $wgSphinxSearch_weights ) ) { $cl->SetFieldWeights( $wgSphinxSearch_weights ); } if ( is_array( $wgSphinxSearch_index_weights ) ) { $cl->SetIndexWeights( $wgSphinxSearch_index_weights ); } if ( $wgSphinxSearch_mode ) { $cl->SetMatchMode( $wgSphinxSearch_mode ); } if ( $this->namespaces && count( $this->namespaces ) ) { $cl->SetFilter( 'page_namespace', $this->namespaces ); } if( !$this->showRedirects ) { $cl->SetFilter( 'page_is_redirect', array( 0 ) ); } if ( $this->categories && count( $this->categories ) ) { $cl->SetFilter( 'category', $this->categories ); wfDebug( "SphinxSearch included categories: " . join( ', ', $this->categories ) . "\n" ); } if ( $this->exc_categories && count( $this->exc_categories ) ) { $cl->SetFilter( 'category', $this->exc_categories, true ); wfDebug( "SphinxSearch excluded categories: " . join( ', ', $this->exc_categories ) . "\n" ); } $cl->SetSortMode( $wgSphinxSearch_sortmode, $wgSphinxSearch_sortby ); $cl->SetLimits( $this->offset, $this->limit, $wgSphinxSearch_maxmatches, $wgSphinxSearch_cutoff ); wfRunHooks( 'SphinxSearchBeforeQuery', array( &$term, &$cl ) ); return $cl; }
function setIndexWeights($weights) { $this->sphinx->SetIndexWeights($weights); return $this; }
<?php $Timer1 = new timer(); //计时器 $Timer1->start(); $sphinx = new SphinxClient(); $sphinx->SetServer("localhost", 9312); if ($irmod == '1') { $sphinx->SetMatchMode(SPH_MATCH_EXTENDED2); } // else if($irmod == '2') // $sphinx->SetMatchMode(SPH_MATCH_PHRASE); #$sphinx->SetSortMode(SPH_SORT_RELEVANCE); // $sphinx->SetSortMode(SPH_SORT_EXTENDED,"@weight DESC");########### $sphinx->SetSortMode(SPH_SORT_EXPR, "hits*0.1+@weight*5"); $sphinx->setLimits(0, 1000, 1000); $sphinx->SetIndexWeights(array("title" => 50, "keywords" => 10, "description" => 5)); $result = $sphinx->query($keyword, "mysql"); echo "<pre>"; // print_r($result); echo "</pre>"; $ids = join(",", array_keys($result['matches'])); $row_num = $result['total']; $Timer1->stop(); if ($row_num <= 0) { echo " <font style='font-weight:bold;color:#f00;'>没有您想要的结果...</font>"; } else { # $Timer2=new timer(); # $Timer2->start();//////////////// $gPageSize = 10; //每页显示记录数 $page = $_GET['page'];