org.carrot2.source.google
Class GoogleDocumentSource

java.lang.Object
  extended by org.carrot2.core.ProcessingComponentBase
      extended by org.carrot2.source.SearchEngineBase
          extended by org.carrot2.source.MultipageSearchEngine
              extended by org.carrot2.source.google.GoogleDocumentSource
All Implemented Interfaces:
IDocumentSource, IProcessingComponent

public class GoogleDocumentSource
extends MultipageSearchEngine

A IDocumentSource fetching search results from Google JSON API. Please note that this document source cannot deliver more than 32 search results.

See Also:
Google AJAX API

Nested Class Summary
 
Nested classes/interfaces inherited from class org.carrot2.source.MultipageSearchEngine
MultipageSearchEngine.SearchEngineResponseCallable, MultipageSearchEngine.SearchMode, MultipageSearchEngine.SearchRange
 
Field Summary
 String apiKey
          Google API Key.
static String CARROTSEARCH_API_KEY
          Google API key assigned to Carrot2/ Carrot Search.
 boolean keepHighlights
          Keep query word highlighting.
 String referer
          Request referer.
 String serviceUrl
          Service URL.
 
Fields inherited from class org.carrot2.source.MultipageSearchEngine
searchMode
 
Fields inherited from class org.carrot2.source.SearchEngineBase
compressed, documents, query, results, resultsTotal, start, statistics
 
Constructor Summary
GoogleDocumentSource()
           
 
Method Summary
protected  void afterFetch(SearchEngineResponse response)
          Called after a single search engine response has been fetched.
protected  Callable<SearchEngineResponse> createFetcher(MultipageSearchEngine.SearchRange bucket)
          Subclasses should override this method and return a MultipageSearchEngine.SearchEngineResponseCallable instance that fetches search results in the given range.
 void process()
          Performs the processing required to fulfill the request.
 
Methods inherited from class org.carrot2.source.MultipageSearchEngine
collectDocuments, process, runQuery
 
Methods inherited from class org.carrot2.source.SearchEngineBase
clean, urlEncode
 
Methods inherited from class org.carrot2.core.ProcessingComponentBase
afterProcessing, beforeProcessing, dispose, getContext, getSharedExecutor, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.carrot2.core.IProcessingComponent
afterProcessing, beforeProcessing, dispose, init
 

Field Detail

CARROTSEARCH_API_KEY

public static final String CARROTSEARCH_API_KEY
Google API key assigned to Carrot2/ Carrot Search. Use your own, please.

See Also:
Constant Field Values

serviceUrl

public String serviceUrl
Service URL. Google web search service URL.

Attribute label:
Service URL
Attribute level:
Advanced
Attribute group:
Service

referer

public String referer
Request referer. Please do not use the default value when deploying this component in production environments. Instead, put the URL to your application here.

Attribute label:
Referer
Attribute level:
Advanced
Attribute group:
Service

keepHighlights

public boolean keepHighlights
Keep query word highlighting. Google by default highlights query words in snippets using the bold HTML tag. Set this attribute to true to keep these highlights.

Attribute label:
Keep highlights
Attribute level:
Advanced
Attribute group:
Postprocessing

apiKey

public String apiKey
Google API Key. Please do not use the default key when deploying this component in production environments. Instead, apply generate and use your own key.

See Also:
Google AJAX signup
Attribute label:
Google API Key
Attribute level:
Advanced
Attribute group:
Service
Constructor Detail

GoogleDocumentSource

public GoogleDocumentSource()
Method Detail

process

public void process()
             throws ProcessingException
Description copied from interface: IProcessingComponent
Performs the processing required to fulfill the request. This method is called once per request.

Specified by:
process in interface IProcessingComponent
Overrides:
process in class ProcessingComponentBase
Throws:
ProcessingException - when processing failed. If thrown, the IProcessingComponent.afterProcessing() method will be called and the component will be ready to accept further requests or to be disposed of. Finally, the exception will be rethrown from the controller method that caused the component to perform processing.

createFetcher

protected Callable<SearchEngineResponse> createFetcher(MultipageSearchEngine.SearchRange bucket)
Description copied from class: MultipageSearchEngine
Subclasses should override this method and return a MultipageSearchEngine.SearchEngineResponseCallable instance that fetches search results in the given range.

Note the query (if any is required) should be passed at the concrete class level. We are not concerned with it here.

Specified by:
createFetcher in class MultipageSearchEngine
Parameters:
bucket - The search range to fetch.

afterFetch

protected void afterFetch(SearchEngineResponse response)
Description copied from class: SearchEngineBase
Called after a single search engine response has been fetched. The concrete implementation may want to override this empty implementation to e.g., clean or otherwise postprocess the returned results.

Overrides:
afterFetch in class SearchEngineBase


Copyright (c) Dawid Weiss, Stanislaw Osinski