Skip to content

o19s/relevant-search-book

Repository files navigation

Relevant Search

Code and Examples for Relevant Search by Doug Turnbull and John Berryman. Published by Manning Publications.

Relevant Search is all about leveraging Solr and Elasticsearch to build more intelligent search applications with intuitive results!

How to run

Install Python

Examples for this book are written in Python 2.7 and use iPython notebook. The first thing you'll need to do is install Python, pip (the Python package installer).

  1. Install Python for your platform here. For Windows we recommend the ActivePython distribution.
  2. Install pip, the Python installer, by simply running easy_install pip

Install Elasticsearch

The examples expect Elasticsearch to be hosted at localhost:9200. So you'll need to install Elasticsearch to work with the examples. There's two ways to install Elasticsearch

Recommended: Vagrant

Vagrant is a tool for installing and provisioning virtual machines locally for development purposes. If you've never used vagrant, you can follow the installation instructions here. OpenSource Connections maintains a basic Elasticsearch vagrant box here.

To use the vagrant box

  1. Install vagrant

  2. Clone the Elasticsearch vagrant box from Github locally

    git clone [email protected]:o19s/elasticsearch-vagrant.git
    
  3. Provision the Vagrant box (this install Elasticsearch and turns the box on)

    cd elasticsearch-vagrant
    vagrant up --provision
    
  4. Confirm Elasticsearch is running

curl -XGET http://localhost:9200

or visit this URL in your browser.

You should see JSON returned from the Elasticsearch instance. Something like:

   {
     "name" : "Mary Zero",
     "cluster_name" : "elasticsearch",
     "version" : {
       "number" : "2.0.0-rc1",
       "build_hash" : "4757962b01a4d837af282f90df9e1fbdb68b524e",
       "build_timestamp" : "2015-10-01T10:06:08Z",
       "build_snapshot" : false,
       "lucene_version" : "5.2.1"
     },
     "tagline" : "You Know, for Search"
   }
  1. When you're done working with examples, turn off the Vagrant box
vagrant halt

Locally on Your Machine

Follow Elasticsearch's instructions to install Elasticsearch on your machine.

Running The Python Examples

The examples are written in Python 2.7 in ipython notebooks depending only on a few basic libraries. The only external library needed is the requests HTTP library. Some of the external APIs require API keys (for example TMDB, you can obtain one here).

To run the IPython Notebook Examples

  1. First ensure you have git, python 2.7 and pip installed and in your PATH

  2. Then use the following commands to install the required dependencies

git clone [email protected]:o19s/relevant-search-book.git
cd relevant-search-book
pip install requests
pip install jupyter
cd ipython/
  1. Launch!

ipython notebook

  1. Play!

Switch to your default browser where the Ipython examples are ready for you to experiment with. Keep in mind many examples are order dependent, so you can't just jump to an interesting listing and run it. Indexing commands with certain settings and what not need to be run. Be sure to run the prior ipython notebook commands too!

Happy Searching!