# Search: Integration patterns

## Table of Contents

- [Agent tool calling](#agent-tool-calling)
  - [Separate expansion tool](#separate-expansion-tool)
- [RAG source expansion](#rag-source-expansion)
  - [When to paginate](#when-to-paginate)
- [News monitoring](#news-monitoring)
- [Entity and local lookup](#entity-and-local-lookup)
- [Academic research](#academic-research)
- [Product intelligence](#product-intelligence)
- [Vertical routing](#vertical-routing)
- [Query expansion](#query-expansion)
- [See also](#see-also)

---

This page collects the most common ways teams integrate `microlink.search` into production systems. Each pattern includes the surface choice, the query strategy, and the expansion depth that makes sense for the workflow.

## Agent tool calling

Expose `microlink.search(query, options)` as a tool and let the model decide when to search, which surface to use, and when to expand:

```js
importcreateClientfrom'microlink.io'

constmicrolink=createClient({

apiKey:process.env.MICROLINK_API_KEY

})

constsearchTool={

name:'web_search',

description:

'Search the web for current information. Returns structured results.',

parameters:{

query:{type:'string',description:'The search query'},

type:{

type:'string',

enum:['search','news','scholar','shopping','images','places'],

description:'Which search surface to use'

}

},

execute:async({query,type='search'})=>{

constpage=awaitmicrolink.search(query,{type})

returnpage.results.map(r=>({

title:r.title,

url:r.url,

description:r.description

}))

}

}
```

The key insight: keep the tool result lightweight. Return `title`, `url`, and `description` from the first call. If the model needs full page content, expose the [markdown](https://microlink.io/docs/sdk/methods/markdown) method as a second tool.

### Separate expansion tool

```js
constexpandTool={

name:'read_page',

description:'Fetch the full content of a URL as Markdown.',

parameters:{

url:{type:'string',description:'URL to read'}

},

execute:({url})=>microlink.markdown(url)

}
```

This two-tool pattern gives the model explicit control over cost and depth.

## RAG source expansion

Start with search to find relevant sources, then expand the best matches into your retrieval pipeline:

```js
constpage=awaitmicrolink.search('site:openai.com function calling guide')

constdocuments=awaitPromise.all(

page.results.slice(0,3).map(asyncresult=>({

title:result.title,

url:result.url,

content:awaitresult.markdown()

}))

)
```

For broader coverage, combine `autocomplete` to discover related queries, then search each one:

```js
constsuggestions=awaitmicrolink.search('how to fine tune',{

type:'autocomplete'

})

constqueries=suggestions.results.slice(0,5).map(s=>s.value)

constallResults=[]

for(constqueryofqueries){

constpage=awaitmicrolink.search(query)

allResults.push(...page.results)

}
```

### When to paginate

Pagination adds recall at the cost of latency and API calls. Paginate when:

- your query is broad and the first page may miss relevant sources
- you need comprehensive coverage for competitive analysis or literature reviews
- the model's confidence is still low after the first page

```js
letpage=awaitmicrolink.search('vector database benchmarks')

constsources=[...page.results]

if(sources.length<5){

page=awaitpage.next()

sources.push(...page.results)

}
```

## News monitoring

Use `news` with `period` to build monitoring and alerting workflows:

```js
constpage=awaitmicrolink.search('data breach',{

type:'news',

period:'day'

})

constalerts=page.results.map(result=>({

title:result.title,

publisher:result.publisher,

date:result.date,

url:result.url

}))
```

For multi-region monitoring, run parallel queries with different `location` values:

```js
constregions=['us','gb','de','jp']

constresults=awaitPromise.all(

regions.map(asynclocation=>{

constpage=awaitmicrolink.search('regulatory update',{

type:'news',

location,

period:'week'

})

return{location,results:page.results}

})

)
```

## Entity and local lookup

Use `places` or `maps` when your workflow needs business or geographic context:

```js
constpage=awaitmicrolink.search('coworking spaces barcelona',{

type:'places'

})

constlocations=page.results.map(result=>({

name:result.title,

address:result.address,

coordinates:{

lat:result.latitude,

lng:result.longitude

},

rating:result.rating

}))
```

Use `maps` instead of `places` when you also need opening hours, price levels, or Google Place IDs for downstream API calls:

```js
constpage=awaitmicrolink.search('restaurants near times square',{

type:'maps'

})

page.results[0].opening?.hours

// { Monday: '11:00 AM – 10:00 PM', ... }

page.results[0].place?.id

// 'ChIJgTwKgJcpQg0RaSKMYcHeNsQ'
```

## Academic research

Use `scholar` to build literature review or citation analysis workflows:

```js
constpage=awaitmicrolink.search('retrieval augmented generation',{

type:'scholar'

})

constpapers=page.results

.sort((a,b)=>b.citations-a.citations)

.slice(0,5)

.map(result=>({

title:result.title,

year:result.year,

citations:result.citations,

pdf:result.pdf?.url,

url:result.url

}))
```

For research agents, combine `scholar` with content expansion to fetch full papers:

```js
constpage=awaitmicrolink.search('transformer architecture',{

type:'scholar'

})

for(constresultofpage.results.slice(0,3)){

if(result.pdf?.url){

console.log(`PDF available: ${result.pdf.url}`)

}else{

constcontent=awaitresult.markdown()

console.log(`Abstract page: ${content.slice(0,500)}`)

}

}
```

## Product intelligence

Use `shopping` for price monitoring, competitive analysis, and product comparison:

```js
constpage=awaitmicrolink.search('mechanical keyboard',{type:'shopping'})

constproducts=page.results.map(result=>({

name:result.title,

price:result.price.amount,

currency:result.price.symbol,

merchant:result.publisher,

rating:result.rating?.score

}))
```

Prices are already parsed into numeric values, so you can sort, filter, and aggregate without string processing:

```js
constaffordable=products.filter(p=>p.price<150)

constavgPrice=products.reduce((sum,p)=>sum+p.price,0)/products.length
```

## Vertical routing

Instead of a single search tool, route the query to the most appropriate surface based on intent:

```js
constroute=intent=>{

constroutes={

current_events:'news',

product_lookup:'shopping',

academic_paper:'scholar',

local_business:'places',

general:'search'

}

returnroutes[intent]||'search'

}

constpage=awaitmicrolink.search(query,{type:route(detectedIntent)})
```

This reduces noise in the results and gives the downstream consumer exactly the fields it needs.

## Query expansion

Use `autocomplete` to discover related queries before running heavier searches:

```js
constsuggestions=awaitmicrolink.search('how to deploy',{

type:'autocomplete'

})

console.log(suggestions.results.map(s=>s.value))

// [

//   'how to deploy a website',

//   'how to deploy to production',

//   'how to deploy docker container',

//   ...

// ]
```

This is useful for:

- **Coverage**: expand a vague query into specific variants before searching
- **Demand modeling**: understand what people are actually searching for
- **Prompt seeding**: generate suggestions for search UIs or chat interfaces

## See also

- [Search](https://microlink.io/docs/guides/search) — install the SDK and make your first query.
- [Web Search](https://microlink.io/docs/guides/search/search), [News](https://microlink.io/docs/guides/search/news), [Scholar](https://microlink.io/docs/guides/search/scholar), and more — field reference for each surface.
- [Content expansion](https://microlink.io/docs/guides/search/content-expansion) — the two-step retrieval model and when to use `.html()` vs `.markdown()`.