fclose($file); $client->ResetFilters(); // filter_range $client->SetFilterRange("field", 1, 3); $file = fopen("spec/fixtures/data/filter_range.bin", "w"); fwrite($file, $client->FilterOutput()); fclose($file); $client->ResetFilters(); // filter_range_exclude $client->SetFilterRange("field", 1, 3, true); $file = fopen("spec/fixtures/data/filter_range_exclude.bin", "w"); fwrite($file, $client->FilterOutput()); fclose($file); $client->ResetFilters(); // filter_floats $client->SetFilterFloatRange("field", 5.4, 13.5); $file = fopen("spec/fixtures/data/filter_floats.bin", "w"); fwrite($file, $client->FilterOutput()); fclose($file); $client->ResetFilters(); // filter_floats_exclude $client->SetFilterFloatRange("field", 5.4, 13.5, true); $file = fopen("spec/fixtures/data/filter_floats_exclude.bin", "w"); fwrite($file, $client->FilterOutput()); fclose($file); $client->ResetFilters(); // filter_boolean $client->SetFilter("field", array(0, 1)); $file = fopen("spec/fixtures/data/filter_boolean.bin", "w"); fwrite($file, $client->FilterOutput()); fclose($file);
<?php require "spec/fixtures/sphinxapi.php"; $cl = new SphinxClient(); $cl->SetFilterRange('attr1', 10, 20, true); $cl->SetFilter('attr3', array(30, 40, 50)); $cl->SetFilterRange('attr1', 60, 70); $cl->SetFilter('attr2', array(80, 90, 100), true); $cl->SetFilterFloatRange('attr1', 60.8, 70.5); $cl->Query('query');
/** * 设置浮点数范围 * 此调用在已有的过滤器列表中添加新的过滤器。$attribute是属性名, $min 、$max定义了一个浮点数闭区间,$exclude必须是布尔值,它控制是接受匹配的文档(默认模式,即$exclude为false时)还是拒绝它们。 * 只有当索引中$attribute列的值落在$min 和 $max之间(包括$min 和 $max),文档才会被匹配(或者拒绝,如果$exclude值为true)。 */ function floatRange($attribute, $min, $max, $exclude = false) { $this->sphinx->SetFilterFloatRange($attribute, $min, $max, $exclude); return $this; }
<?php require "sphinxapi.php"; $cl = new SphinxClient(); $cl->SetFilterFloatRange('attr', 10.5, 20.3); $cl->Query('query');
/** * @brief 위치 기반 Sphinx 검색 부분 (외부/내부 호출용..) * @param $document_srl 문서 번호 * @param $lat 위도 * @param $lon 경도 * @return 검색된 결과 리스트 */ function getSphinxSearchedResult($document_srl, $lat, $lon) { $s = new SphinxClient(); $oModuleModel =& getModel('module'); $config = $oModuleModel->getModuleConfig('aroundmap'); $s->setServer($config->serverName, $config->serverPort); $s->setLimits(0, 10); $s->setMatchMode(SPH_MATCH_ALL); $s->SetSortMode(SPH_SORT_EXTENDED, '@geodist ASC'); $s->setFilter("document_srl", array($document_srl), true); $s->SetFilterFloatRange("@geodist", 0, 10000); $s->setMaxQueryTime(3); $s->setGeoAnchor("lat", "lon", (double) deg2rad($lat), (double) deg2rad($lon)); $result = $s->query("", "idx_aroundmap"); $ret = array(); if ($result[total_found] > 0) { $ret = $result[matches]; } return $ret; }
public function setFilterFloatRange($attribute, $min, $max, $exclude = false) { $this->sphinx->SetFilterFloatRange($attribute, $min, $max, $exclude); }