<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Examples</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sphinx.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.sphinxclient.html">SphinxClient</a></div> <div class="up"><a href="book.sphinx.html">Sphinx</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="sphinx.examples" class="chapter"> <h1>Examples</h1> <div class="example" id="example-4732"> <p><strong>Example #1 Basic usage example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$s </span><span style="color: #007700">= new </span><span style="color: #0000BB">SphinxClient</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$s</span><span style="color: #007700">-></span><span style="color: #0000BB">setServer</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #0000BB">6712</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$s</span><span style="color: #007700">-></span><span style="color: #0000BB">setMatchMode</span><span style="color: #007700">(</span><span style="color: #0000BB">SPH_MATCH_ANY</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$s</span><span style="color: #007700">-></span><span style="color: #0000BB">setMaxQueryTime</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$s</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(10) { ["error"]=> string(0) "" ["warning"]=> string(0) "" ["status"]=> int(0) ["fields"]=> array(3) { [0]=> string(7) "subject" [1]=> string(4) "body" [2]=> string(6) "author" } ["attrs"]=> array(0) { } ["matches"]=> array(1) { [3]=> array(2) { ["weight"]=> int(1) ["attrs"]=> array(0) { } } } ["total"]=> int(1) ["total_found"]=> int(1) ["time"]=> float(0) ["words"]=> array(1) { ["to"]=> array(2) { ["docs"]=> int(1) ["hits"]=> int(1) } } } </pre></div> </div> </div> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sphinx.constants.html">Predefined Constants</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.sphinxclient.html">SphinxClient</a></div> <div class="up"><a href="book.sphinx.html">Sphinx</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>