IXSSO Queries
It's hard to find good information about querying Microsofts Indexing Server through PHP.  In fact many people don't even know that it's possible.  If you have a PHP website running off a Windows Server and you have several documents you want to be searchable from your site, then this is an important skill to know.

I think one of the main reasons there is so little documentation around for querying the indexing server through PHP is because the PHP community is primarily an open source community that hates Microsoft.  So most PHP sites are run off Apache webservers running Linux that doesn't have the Indexing Server.

Well for those of you looking to see if its possible to take advantage of an IXSSO query in your PHP sites, you'll be happy to know you can create a IXSSO COM object just like you would in a classic ASP site.

Creating a searchable catalog with the Indexing Server is pretty straight forward, but making it work correctly can be a different story.  There are some subtle details that can screw you up down the path.

You can find more information about setting up an Indexing Server catalog here.

You can create the IXSSO.Query object and the IXSSO.Util object pretty much the same way that you would in ASP, except using PHP syntax of course.  Instead of using Server.CreateObject, we will do:
$Q = new COM("ixsso.Query");
$util = new COM("ixsso.util");
Now you have IXSSO objects that you can use just like in classic ASP.  You have access to all the properties that you would have in ASP, except now you use PHP syntax.  First thing we need to do is to set which Indexing Server catalog that we will be querying.
$Q->Catalog = "myCatalog";
You can see we simply specify the name of the catalog that we would like to query.

Next we need to specify what our search terms are going to be.  Most likely this will come from a search textbox somewhere on your site.
$Q->Query = "My Search Terms";
We can use the Indexing Servers Advanced Query Language here, but that's a little beyond the scope of this article.

The other mandatory property that we need to setup is which columns we want the indexing server to return. 
$Q->Columns = "filename, rank, vpath, path, DocTitle, characterization, All";
Did you know that you can create custom meta data columns in your pages that you can define through the indexing server?  I discovered this just recently and I was amazed. 

Characterization is always one of those fields that never works quite right for me.  Unfortunatly this is an important field to have.  It provides summary information about the document.  If this isn't appearing make sure that you have generate abstracts on for your catalog.  Also if your indexing PDF's make sure you have Adobe IFilter installed.

The last two properties that we will set before we execute our query are:
$Q->SortBy = "rank[d]";
$Q->MaxRecords = 200;
One of the greatest things about the indexing server is that it ranks the relevance of the results for you.  So to find the best match article, we just sort by rank decending and the best results will be first in the list.

Having MaxRecords set to 200 might be a bit much, but that's just a preference setting.  We would probably page the results in a real implementation.

Now we have all of our properties setup to query the Indexing Server, we can now go ahead and execute our query
$fileRS = $Q->CreateRecordSet("nonsequential");
This gives us a result set that we can loop through and work with the results.  This should all be very familiar if you have ever run IXSSO queries in classic ASP.

Now that we have executed our IXSSO query, lets examine looping through the results and accessing the fields.  First thing we need to do is make sure that our query return some results.
if(!$fileRS->RecordCount == 0) {
I'm not sure if you need the MoveFirst call here, but it's good practice to put it there anyway.  If this failed we could display an error message informing the user that no results were found.

Now lets loop through each record and display them in a simple table:
while($i < $fileRS->RecordCount) {
echo '<tr>
<td style="width: 100px;">'
. $fileRS->fields['rank']->value . '</td>' .
<td><a href="myPath/'
. $fileRS->fields['filename']->value . '">' .
$fileRS->fields['DocTitle']->value . '</a></td>
For some reason, trying to figure out how to access the fields values was exceedingly difficult for me to figure out.  I had tried every combination that I could think of, and nothing worked.  Plus I couldn't find any documentation anywhere that showed an example.  So hopefully this will make your learning expirence easier than my was.

Now at the bottom of the loop we just need to move to the next record and increment our iterator.
That's it.  You now have the knowledge to create a document search for your PHP sites running on a Windows box.