<!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>Basic usage</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="swish.examples.html">Examples</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.swish.html">Swish Functions</a></div> <div class="up"><a href="swish.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="swish.examples-basic" class="section"> <h2 class="title">Basic usage</h2> <p class="para"> <div class="example" id="example-4733"> <p><strong>Example #1 Basic search query</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">try {<br /><br /> </span><span style="color: #0000BB">$swish </span><span style="color: #007700">= new </span><span style="color: #0000BB">Swish</span><span style="color: #007700">(</span><span style="color: #DD0000">"index.swish-e"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$results </span><span style="color: #007700">= </span><span style="color: #0000BB">$swish</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"test OR text"</span><span style="color: #007700">);<br /><br /> echo </span><span style="color: #DD0000">"Found "</span><span style="color: #007700">, </span><span style="color: #0000BB">$results</span><span style="color: #007700">-></span><span style="color: #0000BB">hits</span><span style="color: #007700">, </span><span style="color: #DD0000">" results\n"</span><span style="color: #007700">;<br /> while (</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$results</span><span style="color: #007700">-></span><span style="color: #0000BB">nextResult</span><span style="color: #007700">()) {<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 /> break; </span><span style="color: #FF8000">//break after the first result<br /> </span><span style="color: #007700">}<br /><br />} catch (</span><span style="color: #0000BB">SwishException $e</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Error: "</span><span style="color: #007700">, </span><span style="color: #0000BB">$e</span><span style="color: #007700">-></span><span style="color: #0000BB">getMessage</span><span style="color: #007700">(), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para">The above example will output something similar to:</p> <div class="example-contents screen"> <div class="cdata"><pre> Found 9 results object(SwishResult)#3 (8) { ["swishreccount"]=> int(1) ["swishrank"]=> int(1000) ["swishfilenum"]=> int(10) ["swishdbfile"]=> string(13) "index.swish-e" ["swishdocpath"]=> string(23) "README.SUBMITTING_PATCH" ["swishtitle"]=> NULL ["swishdocsize"]=> int(4557) ["swishlastmodified"]=> int(1072136752) } </pre></div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="swish.examples.html">Examples</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.swish.html">Swish Functions</a></div> <div class="up"><a href="swish.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>