org.carrot2.source.microsoft
Class Bing2DocumentSource

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.microsoft.Bing2DocumentSource
All Implemented Interfaces:
IDocumentSource, IProcessingComponent
Direct Known Subclasses:
Bing2ImageDocumentSource, Bing2NewsDocumentSource, Bing2WebDocumentSource

public abstract class Bing2DocumentSource
extends MultipageSearchEngine

A base IDocumentSource serving requests to Microsoft Bing API, version 2. We model this into separate subclasses, specific to a particular request type (web, image, news). In theory one could request web and news results at once, but in practice this is difficult when paging is also needed (because they have different limits).

See Also:
"http://msdn.microsoft.com/en-us/library/dd251056.aspx"

Nested Class Summary
static class Bing2DocumentSource.BingResponse
           
static class Bing2DocumentSource.ImageResponse
           
static class Bing2DocumentSource.ImageResult
           
static class Bing2DocumentSource.NewsResponse
           
static class Bing2DocumentSource.NewsResult
           
static class Bing2DocumentSource.Thumbnail
           
static class Bing2DocumentSource.WebResponse
           
static class Bing2DocumentSource.WebResult
           
 
Nested classes/interfaces inherited from class org.carrot2.source.MultipageSearchEngine
MultipageSearchEngine.SearchEngineResponseCallable, MultipageSearchEngine.SearchMode, MultipageSearchEngine.SearchRange
 
Field Summary
 AdultOption adult
          Adult search restriction (porn filter).
 String appid
          Microsoft-assigned application ID for querying the API.
static String CARROTSEARCH_APPID
          Application ID assigned to Carrot Search s.c.
 MarketOption market
          Language and country/region information for the request.
protected static int MAX_CONCURRENT_THREADS
          Maximum concurrent threads from all instances of this subcomponents sending requests to Bing.
 String options
          Miscellaneous request options.
 
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
Bing2DocumentSource(SourceType sourceType)
          Initialize with a fixed source type.
 
Method Summary
protected  void addIfNotEmpty(ArrayList<org.apache.http.NameValuePair> params, String paramName, Object value)
          Add a parameter if argument is not an empty string.
protected  void appendSourceParams(ArrayList<org.apache.http.NameValuePair> params)
          Append any source-specific parameters.
protected  Callable<SearchEngineResponse> createFetcher(MultipageSearchEngine.SearchRange bucket)
          Create a single page fetcher for the search range.
abstract  void process()
          Make this abstract so that subclasses override.
 
Methods inherited from class org.carrot2.source.MultipageSearchEngine
collectDocuments, process, runQuery
 
Methods inherited from class org.carrot2.source.SearchEngineBase
afterFetch, 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_APPID

public static final String CARROTSEARCH_APPID
Application ID assigned to Carrot Search s.c. Please use your own if you plan to use Bing with Carrot2.

See Also:
Constant Field Values

MAX_CONCURRENT_THREADS

protected static final int MAX_CONCURRENT_THREADS
Maximum concurrent threads from all instances of this subcomponents sending requests to Bing.

See Also:
Constant Field Values

appid

public String appid
Microsoft-assigned application ID for querying the API. Please generate your own ID for production deployments and branches off the Carrot2.org's code.

Attribute label:
Application ID
Attribute level:
Advanced
Attribute group:
Service

market

public MarketOption market
Language and country/region information for the request.

Attribute label:
Market
Attribute level:
Basic
Attribute group:
Results filtering

adult

public AdultOption adult
Adult search restriction (porn filter).

Attribute label:
Safe Search
Attribute level:
Medium
Attribute group:
Results filtering

options

public String options
Miscellaneous request options. Bing provides the following options:

Options should be space-separated.

Attribute label:
Request Options
Attribute level:
Advanced
Attribute group:
Miscellaneous
Constructor Detail

Bing2DocumentSource

public Bing2DocumentSource(SourceType sourceType)
Initialize with a fixed source type.

Method Detail

createFetcher

protected final Callable<SearchEngineResponse> createFetcher(MultipageSearchEngine.SearchRange bucket)
Create a single page fetcher for the search range.

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

addIfNotEmpty

protected void addIfNotEmpty(ArrayList<org.apache.http.NameValuePair> params,
                             String paramName,
                             Object value)
Add a parameter if argument is not an empty string.


process

public abstract void process()
                      throws ProcessingException
Make this abstract so that subclasses override.

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.

appendSourceParams

protected void appendSourceParams(ArrayList<org.apache.http.NameValuePair> params)
Append any source-specific parameters.



Copyright (c) Dawid Weiss, Stanislaw Osinski