Database Articles

  Home arrow Database Articles arrow Page 23 - Creating a Search Application
DATABASE ARTICLES

Creating a Search Application
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 16
    2003-07-15

    Table of Contents:
  • Creating a Search Application
  • Database Usage
  • Creating a Search Application
  • Searching
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Creating a Search Application -


    (Page 23 of 29 )

    In this function we will do an exact keyword search. This search is relatively straightforward, as it only consists of a single SQL query. Because the number of search terms can change, we need to dynamically create the query. This query will result in URLs being returned along with the number of times those URLs contained the search terms. The results will be ordered from highest to lowest by the number of search term matches.

    This function will return the data from the query, or FALSE if there were not any rows in the result set.

    <?php
    function doSearch() {
        
    $match "keywords.keyword in ('"
               
    $this-&gt;_searchterms[0] . "'";
        for (
    $i 1$i &lt$this-&gt;_numterms$i++) {
            
    $match .= ", '" $this-&gt;_searchterms[$i] . "'";
        }
        
    $match .= ")";
        
    $query "SELECT urls.url, count(*) as counter "
               
    "FROM urls, keywords "
               
    "WHERE $match "
               
    "AND keywords.url_id = urls.id "
               
    "GROUP BY keywords.url_id "
               
    "ORDER BY counter DESC";
        
    $result $this-&gt;_db-&gt;fetch($query);
        if (
    count($result) &gt0)
            
    $return $result;
        else
            
    $return FALSE;

        return 
    $return;
    }
    ?>

    More Database Articles Articles
    More By Matt Wade

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap