PHP Classes
elePHPant
Icontem

File: Search1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eric Chipko  >  CISVC  >  Search1.php  >  Download  
File: Search1.php
Role: Auxiliary script
Content type: text/plain
Description: A non-class version of SEARCH.PHP
Class: CISVC
Encapsulates Microsoft Indexing Service
Author: By
Last change:
Date: 11 years ago
Size: 8,920 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php
   
   
require_once("../phpsessionclass/session.inc.php");
   
$bNewQuery = FALSE;
   
$bUseSavedQuery = FALSE;
   
$strSearchString = "";
    if (
$_SERVER['REQUEST_METHOD']="POST") {
       
$strSearchString = $_REQUEST['SearchString'];
       
$strPG = $_REQUEST['pg'];
        if (
$strPG <> "") {
           
$iNextPageNumber = $strPG;
           
$bNewQuery = FALSE;
           
$bUseSavedQuery; $bUseSavedQuery = TRUE;
        } else {
           
$bNewQuery = ($strSearchString <> "");
        }
// end if
   
} // end if
   
   
function session_dump() {
       
// dumps info about a session
       
$session_array = explode(";",session_encode());
       
$html = "<br/><!-- SESSION VARIABLES DUMP\n\n";
        for (
$x = 0; $x < count($session_array); $x++) {
           
$html .= " $session_array[$x] \n";
        }
        
$html .= " -->\n\n";
        return
$html;
    }
// end function session_dump

   
?>
<style type="text/css">
<!--
.pagetitle {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: x-large;
    font-weight: bold;
}
.wdAbstract {
    font-style: italic;
    font-weight: bold;
}
.url {
    font-size: smaller;
    font-style: italic;
}
.filesize {
    font-size: smaller;
    font-style: italic;
}
.filetime {
    font-size: smaller;
    font-style: italic;
}
.characterization {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: smaller;
}
-->
</style>
</head>

<body>
<p class="pagetitle">Sample PHP Search Form</p>
<table width="75%" border="0">
  <tr>
    <td>Enter your query below</td>
  </tr>
  <tr>
    <td><form name="form1" id="form1" method="post" action="<?php echo($_SERVER['SCRIPT_NAME']); ?>">
        <table width="100%" border="0">
          <tr>
            <td width="83%"><input name="SearchString" type="text" id="SearchString" size="80" maxlength="100" value="<?=$strSearchString?>" /></td>
            <td width="17%"><input type="submit" name="Submit" value="New Query" /></td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
<?php
   
if ($strSearchString <> "") {
        if (
$bNewQuery) {
           
$iNextRecordNumber = 1;
           
$oQ = new COM("ixsso.Query");
           
$oUtil = new COM ("ixsso.util");
           
$oQ->Query = $strSearchString;
           
$oQ->SortBy = "rank[d]";
           
$oQ->Columns = "DocTitle, vpath, path, filename, size, write, characterization";
           
$RS = $oQ->CreateRecordSet("nonsequential");
           
$RS->PageSize = 3;
            echo (
"RS.FieldCount = ".$RS->Fields->Count()." RS.RecordCount =".$RS->RecordCount );
           
$bActiveQuery = TRUE;
        } elseif (
$bUseSavedQuery) {
           
$oQ = new COM("ixsso.Query");
           
$oUtil = new COM ("ixsso.util");
           
$oQ->Query = $strSearchString;
           
$oQ->SortBy = "rank[d]";
           
$oQ->Columns = "DocTitle, vpath, path, filename, size, write, characterization";
           
$RS = $oQ->CreateRecordSet("nonsequential");
           
$RS->PageSize = 3;
            echo (
"RS.FieldCount = ".$RS->Fields->Count()." RS.RecordCount =".$RS->RecordCount );
           
$bActiveQuery = TRUE;
       
           
$oSession=new session();
           
$RS->AbsolutePage = $iNextPageNumber;
           
$iNextRecordNumber = $RS->AbsolutePosition;

           
/* Unable to re-aquire RS type variables across sessions.
            if ( $oSession->is_registered("oQ") and $oSession->is_registered("RS") ) {
                $oQ=$oSession->get("oQ");
                $RS=$oSession->get("RS");
                echo ("FF".$RS->RecordCount."GG");
                if ( $RS->RecordCount <> -1 and $iNextRecordNumber <> -1 ) {
                    $RS->AbsolutePage = $iNextPageNumber;
                    $iNextRecordNumber = $RS->AbsolutePosition;
                } // end if $RS->RecordCount
                $bActiveQuery = TRUE;
            } else {
                echo ("<p class=\"qfail\"> ERROR - No Saved Query</p>");
            } // end if $oQ and $RS from Session
            */
       
} // end if $bNewQuery or Use old query.
   
} // end if $strSearchString <> ""
   
   
if ($bActiveQuery) {
        if (!
$RS->EOF) {
           
$iLastRecordOnPage = $iNextRecordNumber + $RS->PageSize -1;
           
$iCurrentPage = $RS->AbsolutePage;
            if (
$RS->RecordCount <> -1 and $RS->RecordCount < $iLastRecordOnPage) {
               
$iLastRecordOnPage = $RS->RecordCount;
            }
// end if

           
echo ("<br/>Documents ".$iNextRecordNumber. " to ".$iLastRecordOnPage);
            if (
$RS->RecordCount <> -1) {
                echo (
" of ".$RS->RecordCount);
            }
            echo (
" matching the query ".chr(34)."<I>".$strSearchString."</I>".chr(34).".<p>");
?>
<dl>
<?php while (!$RS->EOF and $iNextRecordNumber <= $iLastRecordOnPage) {
?>

  <p class="abstract">
  <dt>
            <?php echo ($iNextRecordNumber)?>.
            <?php // epc Include some error handling for when all fields are not specified in oQColums
                   
if (empty($RS->Fields["DocTitle"]->value) or
                           
$RS->Fields["DocTitle"]->value=="" or
                           
$RS->Fields["DocTitle"]->value=="0") {?>
<b> <a href="
                        <?=$RS->Fields["vpath"]->value?>
">
                        <?=htmlentities($RS->Fields["filename"]->value)?>
</a></b>
            <?php } else {?>
<b> <a href="<?=$RS->Fields["vpath"]->value?>">
                        <?=htmlentities($RS->Fields["DocTitle"]->value)?>
</a></b>
            <?php }?>
<dd>
            <?php if (is_string($RS->Fields["characterization"]->value) and $RS->Fields["characterization"]->value <> "") {?>
<span class="wdAbstract">Abstract: </span>
                <span class="characterization">
                        <?=htmlentities($RS->Fields["characterization"]->value)?>
</span><br>
            <?php } ?>
<span class="url">
           
                <a href="
                    <?=$RS->Fields["vpath"]->value?>
                ">http://<?=$_SERVER['SERVER_NAME'];?><?=$RS->Fields["vpath"]->value?>
</a> - &nbsp;
                </span>
                <span class="filesize">
                    <?php if ($RS->Fields["size"]->value == "") {?>
(size unknown)
                    <?php } else {?>
size <?=$RS->Fields["size"]->value?> bytes
                    <?php }?>
</span>
                <span class="filetime">
                    <?php if ($RS->Fields["write"]->value == "" or (int)$RS->Fields["write"]->value < 100 ) {?>
(time unknown)
                    <?php } else {?>
<?=date("Y-m-d g:i:s A",$RS->Fields["write"]->value)?> GMT
                    <?php }?>
</span>
               
            </dd>
<?php $RS->MoveNext();
            ++
$iNextRecordNumber;
            }
// end while
?> </p>
            </dl>
            <p></p><br/>
<?php } else {
            if (
$iNextRecordNumber == 1) {
                echo (
"<p>No documents matched the query ".chr(34).$strSearchString.chr(34)."</p>");
            } else {
                echo (
"<p>No more docouments in the query.</p>");
            }
        }
// end if $RS.EOF

       
if ($oQ->OutOfDate) {
            echo (
"<p class=\"qmessage\">The index is out of date</p>");
        }
        if (
$oQ->QueryIncomplete) {
            echo (
"<p class=\"qfail\">The query is too expensive to complte</p>");
        }
        if (
$oQ->QueryTimedOut) {
            echo (
"<p class=\"qfail\">The query took to long to complte</p>");
        }
?>

        <table border="0">
          <tr>
              <?php
           
// PREVIOUS Button
           
$bSaveQuery=FALSE;?>
<?php if ($iCurrentPage > 1 and $RS->RecordCount <> -1) {?>
<td align="left"><form action="<?=$_SERVER['SCRIPT_NAME']?>" method="post">
                    <input type="hidden" name="SearchString" value="<?=$strSearchString?>"/>
                    <input type="hidden" name="pg" value="<?=$iCurrentPage-1?>"/>
                    <input type="submit" value="Previous <?=$RS->PageSize?>" documents/>
                </form>
            </td>
            <?php
            $bSaveQuery
=TRUE;
            }
?>

            <?php if (!$RS->EOF) {?>
<td align="right"><form action="<?=$_SERVER['SCRIPT_NAME']?>" method="post">
                    <input type="hidden" name="SearchString" value="<?=$strSearchString?>"/>
                    <input type="hidden" name="pg" value="<?=$iCurrentPage+1?>"/>
                    <?php
                        $strNextString
= "Next ";
                        if (
$RS->RecordCount <> - 1) {
                           
$iNextSet = $RS->RecordCount - $iNextRecordNumber + 1;
                            if (
$iNextSet > $RS->PageSize) { $iNextSet=$RS->PageSize; }
                           
$strNextString = $strNextString . $iNextSet ." documents";
                        } else {
                           
$strNextString = $strNextString & " page of documents";
                        }
                   
?>
<input type="submit" value="<?=$strNextString?>"/>
                </form>
            </td>
            <?php
            $bSaveQuery
= TRUE;
            }
?>
</tr>
        </table>
Page <?=$iCurrentPage?>
<?php
   
if ($RS->PageCount <> -1 ) { echo (" of ".$RS->PageCount);}
    if (
$bSaveQuery) {
       
// save session information. This doesnt work because the RS cannot be recovered between sessions.
       
$oSession=new session();
       
$oSession->register("oQ",$oQ);
       
$oSession->register("RS",$RS);
        echo
session_dump();
    } else {
       
$RS->Close;
       
$RS = NULL;
       
$oQ = NULL;
        if (
is_object($oSession)) {
           
$oSession->unregister("oQ");
           
$oSession->unregister("RS");
           
$oSession->finish;
        }
    }
// end if $bSaveQuery
   
?>
<?php
   
} elseif (!$bNewQuery) {
        echo (
"");
    } else {
        echo (
"Please enter a word or phrase to search for.");
    }
// end if $bActiveQuery
   
?>

           
</body>

</html>