Code Monkey home page Code Monkey logo

google_cse's Introduction

Google Custom Search

This project is a Ruby API to Google’s Custom Search Engine (www.google.com/cse). This plugin is rewrite plugin from Alex Reisner (github.com/alexreisner/google_custom_search.git), because the old plugin not working.

1. Install

Install either as a Rails plugin:

rails plugin install git://github.com/vodafon/google_cse.git

or as a gem:

# add to Gemfile:
gem "google_cse"

# at command prompt:
bundle install

or as a standalone gem (outside of Rails):

sudo gem install google_cse

2. Configure

You must define a constant in your application called CX_GOOGLE_CSE. For example, if you’re using Rails, create a file config/initializers/google_cse.rb:

CX_GOOGLE_CSE = "..."

You can find the CX value for your custom search engine via the search control panel on Google’s site (click the “Get code” link and you’ll see a hidden “cx” field in the sample HTML form).

3. Use

To perform a search:

results = GoogleCustomSearch.search("Hank Aaron", 0)

The second parameter is a start parameter for search query. 0 - first page (1-10 result), 10 - second page, etc.

The results variable is now a GoogleCustomSearch::ResultSet object:

results.pages            # array of pages data
results.results          # array of result objects

Iterate through the results:

results.results.each do |result|
  result.title           # result title
  result.url             # result URL
  result.description     # excerpt, with terms highlighted
end

Copyright © 2010 Igor Vodafon, released under the MIT license

google_cse's People

Contributors

vodafon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.