Book Image

Sphinx Search Beginner's Guide

By : Abbas Ali
Book Image

Sphinx Search Beginner's Guide

By: Abbas Ali

Overview of this book

Table of Contents (15 chapters)
Sphinx Search
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Time for action - showing search form prefilled with last submitted data


  1. 1. Add the following highlighted code in search.php:

    // Perform the search if we have a search term
    if (!empty($q)) {
    do_search($q, $author, $categories);
    }
    // Get all the categories and their ids
    // This will be used to build the categories filter drop down
    $query = "SELECT id, name FROM categories ORDER BY name";
    foreach ($dbh->query($query) as $row) {
    $viewVars['cat_list'][$row['id']] = $row['name'];
    }
    // Assign the search parameters to view variable
    $viewVars['q'] = $q;
    $viewVars['author'] = $author;
    $viewVars['categories'] = $categories;
    // Render the page
    render('search');
    
    
  2. 2. Modify search.thtml and change or add the following highlighted code:

    <div class="input">
    <label>Search for:</label>
    <input type="text"
    name="q" value="<?php echo $viewVars['q']; ?>" />
    </div>
    <div class="input">
    <label>Author:</label>
    <input type="text"
    name="author" value...