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 - adding attributes to the index


  1. 1. Modify the file /usr/local/sphinx/etc/sphinx-blog.conf to add the code as highlighted next:

    source blog
    {
    type = mysql
    sql_host = localhost
    sql_user = root
    sql_pass =
    sql_db = myblog
    sql_query = \
    SELECT id, title, content, UNIX_TIMESTAMP(publish_date) \
    AS publish_date, author_id FROM posts
    sql_attr_uint = author_id
    sql_attr_timestamp = publish_date
    sql_query_info = SELECT id, title FROM posts WHERE ID=$id
    }
    index posts
    {
    source = blog
    path = /usr/local/sphinx/var/data/blog
    docinfo = extern
    charset_type = sbcs
    }
    indexer
    {
    mem_limit = 32M
    }
    

    Note

    Backslashes (\) used for sql_query are just for clarity. The complete query can be written in one single line.

  2. 2. Run the indexer again to re-index the data:

    $ /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx-blog.conf --all
    
  3. 3. Search for all posts containing the term php, written by Aditya Mooley (author_id = 2):

    $ /usr/local/sphinx/bin/ search --config /usr/local/sphinx/etc/sphinx...