bingsearch

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolName         = "Bing Search API"
	ParamAPIKey      = "apiKey"
	ParamCount       = "count"
	ParamScraperPage = "scraperPage"
)
View Source
const (
	Endpoint      = "https://api.bing.microsoft.com/v7.0/search"
	AuthHeaderKey = "Ocp-Apim-Subscription-Key"
)

Variables

This section is empty.

Functions

func FormatResults

func FormatResults(vals []WebPage) (res string)

Types

type BingClient

type BingClient struct {
	// contains filtered or unexported fields
}

func NewBingClient

func NewBingClient(opts ...Option) *BingClient

func NewFromToolSpec

func NewFromToolSpec(tool *v1alpha1.Tool) (client *BingClient, err error)

func (*BingClient) Search

func (client *BingClient) Search(ctx context.Context, query string) (string, error)

func (*BingClient) SearchGetDetailData

func (client *BingClient) SearchGetDetailData(ctx context.Context, query string) (resp []WebPage, data string, err error)

SearchGetDetailData will try to parse bing search list type webpages and news. Unlike the Search method, it returns a more detailed list of structures, not just a string. Note: only parse search list, not single source page.

type ContractualRules

type ContractualRules struct {
	Type string `json:"_type"`
	Text string `json:"text"`
}

type Creator

type Creator struct {
	Name string `json:"name"`
}
type DeepLink struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	Snippet string `json:"snippet"`
}

type Entities

type Entities struct {
	Value []EntitiesValue `json:"value"`
}

type EntitiesValue

type EntitiesValue struct {
	ID                     string                 `json:"id"`
	EntityPresentationInfo EntityPresentationInfo `json:"entityPresentationInfo"`
	BingID                 string                 `json:"bingId"`
}

type EntityPresentationInfo

type EntityPresentationInfo struct {
	EntityScenario string `json:"entityScenario"`
}

type ErrorResp

type ErrorResp struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type Image

type Image struct {
	ContentURL string    `json:"contentUrl"`
	Thumbnail  Thumbnail `json:"thumbnail"`
}

type News

type News struct {
	ID         string      `json:"id"`
	ReadLink   string      `json:"readLink"`
	NewsValues []NewsValue `json:"value"`
}

type NewsValue

type NewsValue struct {
	ContractualRules []ContractualRules `json:"contractualRules"`
	Name             string             `json:"name"`
	URL              string             `json:"url"`
	Description      string             `json:"description"`
	Provider         []Provider         `json:"provider"`
	DatePublished    time.Time          `json:"datePublished"`
	Category         string             `json:"category"`
	Image            Image              `json:"image,omitempty"`
}

type Option

type Option func(*options)

func WithAPIKey

func WithAPIKey(apiKey string) Option

func WithCount

func WithCount(count int) Option

func WithScraperPage added in v0.2.1

func WithScraperPage(scraperPage bool) Option

type PrimaryImageOfPage

type PrimaryImageOfPage struct {
	ThumbnailURL string `json:"thumbnailUrl"`
	Width        int    `json:"width"`
	Height       int    `json:"height"`
	ImageID      string `json:"imageId"`
}

type Provider

type Provider struct {
	Type  string `json:"_type"`
	Name  string `json:"name"`
	Image Image  `json:"image"`
}

type Publisher

type Publisher struct {
	Name string `json:"name"`
}

type QueryContext

type QueryContext struct {
	OriginalQuery string `json:"originalQuery"`
}

type RankingResponse

type RankingResponse struct {
	Mainline RankingResponseMainline `json:"mainline"`
	Sidebar  RankingResponseSidebar  `json:"sidebar"`
}

type RankingResponseItem

type RankingResponseItem struct {
	AnswerType  string                   `json:"answerType"`
	ResultIndex int                      `json:"resultIndex"`
	Value       RankingResponseItemValue `json:"value"`
}

type RankingResponseItemValue

type RankingResponseItemValue struct {
	ID string `json:"id"`
}

type RankingResponseMainline

type RankingResponseMainline struct {
	Items []RankingResponseItem `json:"items"`
}

type RankingResponseSidebar

type RankingResponseSidebar struct {
	Items []RankingResponseItem `json:"items"`
}

type RespData

type RespData struct {
	Type            string          `json:"_type,omitempty"`
	QueryContext    QueryContext    `json:"queryContext,omitempty"`
	WebPages        WebPages        `json:"webPages,omitempty"`
	Entities        Entities        `json:"entities,omitempty"`
	Videos          Videos          `json:"videos,omitempty"`
	News            News            `json:"news,omitempty"`
	RankingResponse RankingResponse `json:"rankingResponse,omitempty"`
	ErrorResp       *ErrorResp      `json:"error,omitempty"`
}

type SearchTag

type SearchTag struct {
	Name    string `json:"name"`
	Content string `json:"content"`
}

type Thumbnail

type Thumbnail struct {
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	ContentURL string `json:"contentUrl,omitempty"`
}

type Tool

type Tool struct {
	CallbacksHandler callbacks.Handler
	// contains filtered or unexported fields
}

func New

func New(tool *v1alpha1.Tool) (*Tool, error)

New creates a new bing search tool to search on internet

func (Tool) Call

func (t Tool) Call(ctx context.Context, input string) (string, error)

func (Tool) Description

func (t Tool) Description() string

func (Tool) Name

func (t Tool) Name() string

type VideoValue

type VideoValue struct {
	WebSearchURL       string      `json:"webSearchUrl"`
	Name               string      `json:"name"`
	Description        string      `json:"description"`
	ThumbnailURL       string      `json:"thumbnailUrl"`
	DatePublished      string      `json:"datePublished"`
	Publisher          []Publisher `json:"publisher"`
	Creator            Creator     `json:"creator,omitempty"`
	ContentURL         string      `json:"contentUrl"`
	HostPageURL        string      `json:"hostPageUrl"`
	EncodingFormat     string      `json:"encodingFormat"`
	HostPageDisplayURL string      `json:"hostPageDisplayUrl"`
	Width              int         `json:"width"`
	Height             int         `json:"height"`
	Duration           string      `json:"duration,omitempty"`
	MotionThumbnailURL string      `json:"motionThumbnailUrl,omitempty"`
	EmbedHTML          string      `json:"embedHtml"`
	AllowHTTPSEmbed    bool        `json:"allowHttpsEmbed"`
	ViewCount          int         `json:"viewCount"`
	Thumbnail          Thumbnail   `json:"thumbnail"`
	AllowMobileEmbed   bool        `json:"allowMobileEmbed"`
	IsSuperfresh       bool        `json:"isSuperfresh"`
}

type Videos

type Videos struct {
	ID               string       `json:"id"`
	ReadLink         string       `json:"readLink"`
	WebSearchURL     string       `json:"webSearchUrl"`
	IsFamilyFriendly bool         `json:"isFamilyFriendly"`
	Value            []VideoValue `json:"value"`
	Scenario         string       `json:"scenario"`
}

type WebPage

type WebPage struct {
	Title       string
	Description string
	URL         string
	Content     string
}

type WebPages

type WebPages struct {
	WebSearchURL          string          `json:"webSearchUrl"`
	TotalEstimatedMatches int             `json:"totalEstimatedMatches"`
	Value                 []WebPagesValue `json:"value"`
	SomeResultsRemoved    bool            `json:"someResultsRemoved"`
}

type WebPagesValue

type WebPagesValue struct {
	ID                       string             `json:"id"`
	Name                     string             `json:"name"`
	URL                      string             `json:"url"`
	DatePublished            string             `json:"datePublished,omitempty"`
	DatePublishedDisplayText string             `json:"datePublishedDisplayText,omitempty"`
	IsFamilyFriendly         bool               `json:"isFamilyFriendly"`
	DisplayURL               string             `json:"displayUrl"`
	Snippet                  string             `json:"snippet"`
	DeepLinks                []DeepLink         `json:"deepLinks,omitempty"`
	DateLastCrawled          time.Time          `json:"dateLastCrawled"`
	CachedPageURL            string             `json:"cachedPageUrl,omitempty"`
	Language                 string             `json:"language"`
	IsNavigational           bool               `json:"isNavigational"`
	ThumbnailURL             string             `json:"thumbnailUrl,omitempty"`
	PrimaryImageOfPage       PrimaryImageOfPage `json:"primaryImageOfPage,omitempty"`
	SearchTags               []SearchTag        `json:"searchTags,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL