예제 #1
0
            $str_end = $suggestion->getEndOffset();
            $original_string = substr($q, $str_start, $str_end);
            $suggested_q = str_replace($original_string, $suggestion->getWord(), $suggested_q);
        }
        $body .= '<p>Did you mean “<a href="/search/?q=' . urlencode($suggested_q) . '">' . $suggested_q . '</a>”?</p>';
    }
    /*
     * See if the search term consists of a section number.
     */
    if (preg_match(SECTION_REGEX, $q) == TRUE) {
        /*
         * If this is an actual section number that exists in the law, provide a link to it.
         */
        $law = new Law();
        $law->section_number = $q;
        if ($law->exists() === TRUE) {
            $body .= '
			<p><a href="' . $law->url . '">Were you looking for ' . SECTION_SYMBOL . '&nbsp;' . $law->section_number . '?</a></p>';
        }
    }
    /*
     * If there are no results.
     */
    if (count($results) == FALSE) {
        $body .= '<p>No results found.</p>';
    } else {
        /*
         * Store the total number of documents returned by this search.
         */
        $total_results = $results->getNumFound();
        /*
 /**
  * This is used as the preg_replace_callback function that inserts section links into text.
  */
 function replace_sections($matches)
 {
     /*
      * PCRE provides an array-based match listing. We only want the first one.
      */
     $match = $matches[0];
     /*
      * If the section symbol prefixes this match, hack it off.
      */
     if (substr($match, 0, strlen(SECTION_SYMBOL)) == SECTION_SYMBOL) {
         $match = substr($match, strlen(SECTION_SYMBOL . ' '));
     }
     /*
      * Create an instance of the Law class.
      */
     $law = new Law();
     /*
      * Just find out if this law exists.
      */
     $law->section_number = $match;
     $section = $law->exists();
     /*
      * If this isn't a valid section number, then just return the match verbatim -- there's no
      * link to be provided.
      */
     if ($section === FALSE) {
         return $matches[0];
     }
     return '<a class="law" href="/' . $match . '/">' . $matches[0] . '</a>';
 }