Book Image

Apache Solr PHP Integration

By : Jayant Kumar
Book Image

Apache Solr PHP Integration

By: Jayant Kumar

Overview of this book

The Search tool is a very powerful for any website. No matter what type of website, the search tool helps visitors find what they are looking for using key words and narrow down the results using facets. Solr is the popular, blazing fast, open source enterprise search platform from the Apache Lucene project. It is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest websites.This book is a practical, hands-on, end-to-end guide that provides you with all the tools required to build a fully-featured search application using Apache Solr and PHP. The book contains practical examples and step-by-step instructions.Starting off with the basics of installing Apache Solr and integrating it with Php, the book then proceeds to explore the features provided by Solr to improve searches using Php. You will learn how to build and maintain a Solr index using Php, discover the query modes available with Solr, and how to use them to tune the Solr queries to retrieve relevant results. You will look at how to build and use facets in your search, how to tune and use fast result highlighting, and how to build a spell check and auto complete feature using Solr. You will finish by learning some of the advanced concepts required to runa large-scale enterprise level search infrastructure.
Table of Contents (15 chapters)
Apache Solr PHP Integration
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Searches are an integral part of any web application that is built today. Whether it is a content site, a job site, an e-commerce site, or any other website, searches play a very important role in helping the user locate the information that he/she is looking for. As a developer, it is imperative to provide the user of the website with all the possible tools for searching and narrowing down to the required information. Apache Solr is a full text search engine, which provides a large list of features for searches. PHP is the preferred programming language for building websites. This book guides the reader on the integration between PHP and Solr.

When a user performs a search on the website, he wants the results to be relevant based on certain criteria. Let us take the example of an e-commerce website. A search can happen on product names, brand names, model numbers, and product types. Once the results are visible, it is important to provide a set of facets on price, size, and some other features of the products in the search result, which can be used to narrow down the results to exactly what is desired. Autocompleting the search query as the user types and providing spelling suggestions are some of the advanced search functionalities that are visible on some websites.

The idea of this book is to bring attention to these and many other search functionalities that Solr provides to the community of PHP developers and to guide PHP developers who build these websites on exploring and using these search functionalities to build features related to searches into their websites. This book not only provides a quick step-by-step PHP code for fast development of search features but also goes in depth on how the feature actually works on the Solr end. Configurations and tweaking options in Solr and PHP are also discussed for advanced users to help them tweak the functionality as per their requirements.

This book will start with installation of Solr, adding, updating, and deleting documents on Solr using PHP and then exploring the features provided by the Solr search. We will explore the features provided by Solr such as faceting, grouping, boosting, and sorting of results. We will build a spell check and a query autocomplete feature provided by Solr. We will also look at advanced features for scaling search. This book will provide an end-to-end practical guide to building a full featured search application using PHP and Solr.

What this book covers

Chapter 1, Installing and Integrating Solr and PHP, introduces Solr and installs and integrates Solr with PHP on both Windows and Linux environments.

Chapter 2, Inserting, Updating, and Deleting Documents from Solr, provides practical examples on how to use PHP to add, modify, and delete documents from the Solr index.

Chapter 3, Select Query on Solr and Query Modes (DisMax/eDisMax), explains how to run basic search queries on Solr and use different query modes to run some advanced search queries.

Chapter 4, Advanced Queries – Filter Queries and Faceting, digs deeper into search queries and provides practical examples for running filter queries and facets using Solr and PHP.

Chapter 5, Highlighting Results Using PHP and Solr, explains how Solr can be configured for highlighting search results and provides practical examples in PHP for highlighting.

Chapter 6, Debug and Stats Component, explains how Solr calculates relevance, ranks the results of a search query, and explains how index statistics can be obtained.

Chapter 7, Spell Check in Solr, configures Solr for spell check and provides practical example of an autocomplete feature built using PHP and Solr.

Chapter 8, Advanced Solr – Grouping, the MoreLikeThis Query, and Distributed Search, goes in depth on some of the advanced topics in Solr and also explains how Solr can be scaled horizontally.

What you need for this book

You will need a Windows or Linux machine with Apache Web Server configured to run PHP scripts. A file editor for writing code and a web browser to check the output of code execution will be needed. We will be downloading, installing, and configuring Solr as required.

Who this book is for

This book is for PHP developers who need to build and integrate search into their applications. No prior knowledge of Solr is required. Understanding of object oriented programming using PHP would be helpful. Readers should be familiar with the concept of web applications.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in the text are shown as follows: "Call the createPing()function to create the ping query."

A block of code is set as follows:

$config = array(
  "endpoint" => array("localhost" => array("host"=>"127.0.0.1",
"port"=>"8080", "path"=>"/solr", "core"=>"collection1",)
) );

Any command-line input or output is written as follows:

cd ~/solr-4.3.1/example
java –jar start.jar

New terms and important words are shown in italics. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Select collection1 from the dropdown on the left-hand panel. Click on ping and you will see the ping time in milliseconds appear next to the ping link".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.