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!
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).
- Install Python for your platform here. For Windows we recommend the ActivePython distribution.
- Install pip, the Python installer, by simply running
easy_install pip
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
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
-
Install vagrant
-
Clone the Elasticsearch vagrant box from Github locally
git clone git@github.com:o19s/elasticsearch-vagrant.git
-
Provision the Vagrant box (this install Elasticsearch and turns the box on)
cd elasticsearch-vagrant vagrant up --provision
-
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"
}
- When you're done working with examples, turn off the Vagrant box
vagrant halt
Follow Elasticsearch's instructions to install Elasticsearch on your machine.
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
-
First ensure you have git, python 2.7 and pip installed and in your PATH
-
Then use the following commands to install the required dependencies
git clone git@github.com:o19s/relevant-search-book.git
cd relevant-search-book
pip install requests
pip install jupyter
cd ipython/
- Launch!
ipython notebook
- 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!