# Enterprise Search — Cross-Source Lead Intelligence

Search across all connected data sources in a single query to find leads, company information, interaction history, and market intelligence.

## When This Skill Activates

Trigger phrases: "search for [company/topic]", "find [info] across [sources]", "what do we know about [company]", "search everything for [query]", "unified search [topic]"

## How It Works

### Source Priority

Search these sources in order of reliability:

| Priority | Source | What It Finds | Tool |
|----------|--------|---------------|------|
| 1 | Lead Pipeline Data | Existing leads, campaigns, audit logs | Local files |
| 2 | CRM (HubSpot/Pipedrive) | Contacts, deals, interactions | MCP server |
| 3 | Business Registries | Company filings, officers, status | Scrapers |
| 4 | Web Search (Tavily/Google/DDG) | News, websites, public info | Enrichment module |
| 5 | Slack/Teams | Internal discussions, mentions | MCP server |
| 6 | Email (Microsoft 365/Gmail) | Correspondence history | MCP server |
| 7 | Documents (Notion/Confluence) | Internal docs, notes | MCP server |

### Query Decomposition

A single natural language query gets decomposed into source-specific searches:

**Example:** "What do we know about TechCorp Qatar?"

| Source | Translated Query |
|--------|-----------------|
| Lead Pipeline | Search campaign files for "TechCorp" |
| CRM | API query: company name contains "TechCorp" |
| Qatar Registry | `QatarRegistryScraper.search("TechCorp")` |
| Web Search | "TechCorp Qatar company site:linkedin.com OR site:crunchbase.com" |
| Slack | Messages mentioning "TechCorp" in sales channels |

### Filters

Support natural language filters:
- `from:sarah` → filter by author/sender
- `in:#sales` → filter by channel/folder
- `after:2025-01-01` → date range
- `type:email|lead|document|message` → content type
- `source:crm|registry|web` → specific source

### Result Synthesis

```markdown
## Search Results: "[Query]"

### Summary
[2-3 sentence synthesis of the most important findings across all sources]

### Lead Pipeline Data
[Existing leads, campaign history, contact info, GDPR audit entries]

### CRM Records
[Contacts, deals, interaction history, notes]

### Registry Data
[Company filings, officers, status, SIC codes]

### Web Intelligence
[Recent news, website info, social presence]

### Internal Communications
[Relevant Slack threads, emails, documents]

### Confidence Assessment
| Finding | Confidence | Sources |
|---------|-----------|---------|
| [Fact 1] | High | [Multiple sources agree] |
| [Fact 2] | Medium | [Single source, credible] |
| [Fact 3] | Low | [Unverified, needs confirmation] |
```

## Digest Generation

Generate periodic digests of activity across all sources:

### Daily Digest
- New leads scraped today
- Emails sent and their status
- CRM updates and new contacts
- Mentions of target companies in Slack/email
- Action items and follow-ups due

### Weekly Digest
- Campaign performance summary
- Pipeline movement (stage changes)
- New companies discovered
- Competitive intelligence gathered
- Compliance check summary

## Integration with Lead Pipeline

### Local Data Search
```python
from lead_pipeline.types import LeadStore
import json, glob

# Search all campaign files
campaigns = glob.glob("~/.lead_pipeline/data/campaign_*.json")
for campaign_file in campaigns:
    leads = LeadStore().load_leads(campaign_id)
    # Filter leads matching query
```

### Registry Search
```python
from lead_pipeline.scrapers import UKCompaniesHouseScraper, QatarRegistryScraper

# Search both registries in parallel
uk_results = await uk_scraper.search(query)
qatar_results = await qatar_scraper.search(query)
```

### Enrichment Search
```python
from lead_pipeline.enrichment import LeadEnricher

# Use enrichment module for web search
contact_info = await enricher.enrich(company)
```

## Key Rules
- Search local/pipeline data FIRST — it's fastest and most relevant
- Deduplicate across sources — same company may appear in multiple places
- Attribute every finding to its source
- Score confidence based on source count and recency
- Respect rate limits on external sources (especially registries)
- GDPR: searching doesn't mean processing — log appropriately
