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

Grouping search results


At times we may need to group our search results by an attribute. For example, to show monthly statistics about our blog posts we will need to group the posts by publish_date, or to show count of books by a particular author we will need to group the search results by author.

Sphinx offers a grouping mode which is enabled with SetGroupBy() API call. All matches are assigned to different groups based on group-by value when grouping is used.

Different functions are available to compute the group-by value:

  • SPH_GROUPBY_DAY: Extracts year, month, and day in YYYYMMDD format from the timestamp attribute

  • SPH_GROUPBY_WEEK: Extracts year and first day of the week number in YYYYNNN format from timestamp

  • SPH_GROUPBY_MONTH: Extracts year and month in YYYYMM format from timestamp

  • SPH_GROUPBY_YEAR: Extracts year in YYYY format from timestamp

  • SPH_GROUPBY_ATTR: Attribute value is used for grouping

The function to be used for grouping is:

SetGroupBy ( $attribute, $func, $groupsort...