1<?PHP2 3 $options=Array4 (5' hostname ' = ' localhost ',6' Port ' = ' 8080 ',7' Path ' = ' solr/help_category ',8' WT ' = ' json '9 );Ten $client=NewSolrclient ($options); One Try { A $client-Ping (); -}Catch(Exception $e) { - Exit(' Not Connected '); the } - - $query=Newsolrquery (); - $query->setquery (' title: Account ')); + - $query->setstart (0); + $query->setrows (20); A at $query->addfield (' title ')->addfield (' id ')); - $query->addhighlightfield (' title '); - $query->sethighlight (true); - $query->sethighlightsimplepre ("<span style= ' Color:blue ' >"); - $query->sethighlightsimplepost (' </span> ')); - in $query _response=$client->query ($query); - $response=$query _response-getResponse (); to Var_dump($query _response-Getrequesturl ()); + Var_dump($query _response-getrawrequest ()); - Var_dump($response[' Highlighting ']); You can find the highlighted part by using foreach the if($response[' response '] [' Numfound '] > 0) { * foreach($response[' response '] [' Docs '] as $doc) { $ Echo $doc[' title '];Panax Notoginseng Echo' <br><br> '; - } the } +?>
PHP Search SOLR documentation (with highlighting)