ruby-search-engine
- Author
-
Martin Velez, Michael Yen, Matthew Le
- Copyright
-
Copyright © 2016 Authors
- License
-
MIT
Description
Search the web using Ruby with this fast and lightweight gem, made to prioritize speed and efficiency. Compared to other search gems, this aims to be minimal, easy to use and most importantly, quick. For any inquiries, please feel free to contact us via email or a pull request. I hope you enjoy using the ruby-search-engine as much as we have had while making it!
-Matt Le
Design
The ruby-search-engine performs a low-level Google search using Google’s UDS (User Distributed Search) which will return a JSON object containing the query’s results per page. The object is then parsed and stored into a Ruby hash. From there, depending on the fields entered, the search() method will return the desired fields. There is also the option to specify how many pages will be returned. The usage section provides examples of this.
Fields/options:
-
GsearchResultClass
-
unescapedUrl
-
url
-
visibleUrl
-
cacheUrl
-
title
-
titleNoFormatting
-
content
**Note: fields must be entered as a symbol, ie. :url**
Installation
gem install ruby-search-engine
Usage
For a full example, go to bin/ruby_search_engine.rb
From within your app:
query = ARGV.join(" ")
# gets query from command line, also can use ARGF.read
# or
query = "my query"
# query can be any string
search_engine = SearchEngine.new
results = search_engine.search(query, :url, pages: 2)
# Calls the search method with the query, url for the field and 2 pages.
# results will be an array containing the first 2 pages worth of urls.
You can also provide input via STDIN on the command line.
$ ruby ruby_search_engine.rb QUERY
You can also run the executable via the ruby_cli gem which can help you make a command line app.
For a simple query, defaults to 1 page of results:
$ ./ruby_search_engine.rb QUERY
To specify the number of pages wanted:
$ ./ruby_search_engine.rb -p 2 QUERY
Dependencies
-
Ruby 1.9.1 or greater
-
ruby_cli to run the gem executable (optional)
Alternative Tools
TODO
-
Further optimization?
-
Test to determine limits of current approach, which parses and stores JSON objects.
-
-
Future features
-
Different search engines?
-
Source Code
https://github.com/martinvelez/ruby-search-engine