sphinx autocomplete CALL SNIPPETS摘录不返回结果集

时间:2013-11-26 16:02:59

标签: sphinx

我能够从print_r获得结果集($ stmt-> fetchAll());但是,我无法从print_r($ r)获得结果集;以下是https://github.com/adriannuta/SphinxAutocompleteExample的确切代码。唯一的变化是sphinx.conf文件中的sql_query。

ajax_suggest_excerpts.php

require_once 'common.php';
require_once 'functions.php';
$indexes = 'simplecomplete';
$arr =array();
$q = trim($_GET['term']);
$stmt = $ln_sph->prepare("SELECT * FROM $indexes WHERE MATCH(:match) LIMIT 0,10 OPTION ranker=sph04");


$aq = explode(' ',$q);
if(strlen($aq[count($aq)-1])<3){
$query = $q;
}else{
$query = $q.'*';
}
$stmt->bindValue(':match', $query,PDO::PARAM_STR);
$stmt->execute();

$docs = array();
$title = "";    
$stmsnp = $ln_sph->prepare("CALL SNIPPETS(:doc,'simplecomplete',:query)");
$stmsnp->bindValue(':query',$query,PDO::PARAM_STR);
$stmsnp->bindParam(':doc',$title,PDO::PARAM_STR);

print_r($stmt->fetchAll()); //THIS RETURNS RESULT SET

foreach($stmt->fetchAll() as $r){
    $title = $r['city'];
    $stmsnp->execute();
    $r = $stmsnp->fetch();  
    print_r($r); //THIS DOES NOT. 
    $arr[] = array('id' => utf8_encode($r['city']),'label' =>utf8_encode( $r['city']));
}

echo json_encode($arr);
exit();

sphinx.conf中

source simplecomplete
{
    type                = mysql
    sql_host        = localhost
    sql_user        = swflorib
    sql_pass        = cii65419
    sql_db          = swflorib_db
    sql_port        = 3306  # optional, default is 3306 

    sql_query           = SELECT id, Sic_Code_description, Sic_Code6_Description, City, hidden_keywords FROM no_admin_emails GROUP BY Company_Name
    sql_field_string    = Sic_Code_description  
    sql_field_string    = Sic_Code6_Description
    sql_field_string    = City
    sql_field_string    = hidden_keywords
}

index simplecomplete
{
    source              = simplecomplete
    path                = /usr/local/sphinx/var/data/simplecomplete
    docinfo             = extern
    charset_type        = utf-8
    min_word_len        = 3
    enable_star         = 1
    min_prefix_len      = 3
}

1 个答案:

答案 0 :(得分:0)

来自fetchAll的文档 http://us3.php.net/manual/en/pdostatement.fetchall.php

  

返回一个包含结果集中所有剩余行的数组。

因此print_r()中的fetchAll从数据库中获取所有行。 foreach()中的fetchAll没有剩下的行来获取!

看起来像是对PHP / pdo的误解。