 
 GOOGLE_API_KEY = process.env.GOOGLE_API_KEY
 GOOGLE_CUSTOM_SEARCH = process.env.GOOGLE_CUSTOM_SEARCH
-BING_SEARCH_API_KEY = process.env.BING_SEARCH_API_KEY
-USE_BING_V5 = process.env.USE_BING_V5
-MAX_RESULTS = process.env.MAX_SEARCH_RESULTS or 5
+MAX_RESULTS = process.env.MAX_SEARCH_RESULTS or 3
 
 DEF_SERVER_ERROR = "I'm unable to process your request at this time due to a server error. Please try again later."
 

        results += "About #{data.searchInformation.formattedTotalResults} results (#{data.searchInformation.formattedSearchTime} seconds)."
        results

# Azure Marketplace - Bing Search API v2
class BingSearch extends ISearch
    _search: (query, cb) ->
        @robot.logger.info "hubot-search: using Azure Marketplace - Bing Search API v2 (Web Results Only)"
        opts =
            auth: "#{BING_SEARCH_API_KEY}:#{BING_SEARCH_API_KEY}"
        params =
            $format: "json"
            $top: MAX_RESULTS
            Query: "'#{query}'"
        # @robot.logger.debug "hubot-search: Bing Search API v2 params : #{params}"
        @robot.http("https://api.datamarket.azure.com/Bing/SearchWeb/v1/Web", opts)
            .header("content-type", "application/json")
            .query(params)
            .get() cb

    _hasResults: (data) ->
        data.d?.results?.length > 0

    _format: (data) ->
        results = ""
        for result, i in data.d.results
            results += "#{i+1}. #{result.Title}: #{result.Description} (#{result.Url})\n"
        results

# Microsoft Cognitive Services - Bing Search API v5
class BingSearchV5 extends ISearch
    _search: (query, cb) ->
        @robot.logger.info "hubot-search: using Microsoft Cognitive Services - Bing Search API v5 (Web only)"
        params =
            q: query
            count: MAX_RESULTS
        @robot.http("https://api.cognitive.microsoft.com/bing/v5.0/search")
            .header("content-type", "application/json")
            .header("Ocp-Apim-Subscription-Key", BING_SEARCH_API_KEY)
            .query(params)
            .get() cb

    _hasResults: (data) ->
        data.webPages?.totalEstimatedMatches > 0

    _format: (data) ->
        results = ""
        for result, i in data.webPages.value
            results += "#{i+1}. #{result.name}: #{result.snippet} (#{result.url})\n"
        results

module.exports = (robot) ->
    # Listener: Google Custom Search

                res.send results
    else
        robot.logger.warning "hubot-search: Missing GOOGLE_API_KEY or GOOGLE_CUSTOM_SEARCH in environment. Google Custom Search will not be available."
