Search Operations
Comprehensive Search API Documentation
Altus 4 provides powerful search capabilities that enhance MySQL's native full-text search with AI-powered optimizations, semantic understanding, and multi-database federation.
Search Overview
Search Modes
Altus 4 supports three distinct search modes:
- Natural Language - Human-readable queries with automatic optimization
- Boolean - Traditional boolean operators (AND, OR, NOT) with MySQL syntax
- Semantic - AI-powered semantic search using OpenAI embeddings
Search Architecture
graph TD
A[Search Request] --> B[Query Processing]
B --> C{Search Mode}
C -->|Natural| D[Natural Language Processing]
C -->|Boolean| E[Boolean Query Parser]
C -->|Semantic| F[AI Semantic Analysis]
D --> G[Multi-Database Execution]
E --> G
F --> G
G --> H[Result Aggregation]
H --> I[AI Enhancement]
I --> J[Cache Storage]
J --> K[Formatted Response]Core Search Endpoint
Execute Search
Perform a search across one or more connected databases with comprehensive options.
Endpoint: POST /api/v1/search
Headers:
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/jsonRequest Body:
{
"query": "database performance optimization techniques",
"databases": ["db_uuid_1", "db_uuid_2"],
"tables": ["articles"],
"columns": ["title", "content"],
"searchMode": "natural",
"limit": 20,
"offset": 0,
"includeAnalytics": false
}Request Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Search query (1-500 characters) |
databases | array | No | Array of database UUIDs to search (optional) |
tables | array | No | Specific tables to search |
columns | array | No | Specific columns to search |
searchMode | enum | No | natural, boolean, semantic (default: natural) |
limit | number | No | Max results (1-100, default: 20) |
offset | number | No | Results offset for pagination (default: 0) |
includeAnalytics | boolean | No | Include search analytics (default: false) |
Response:
{
"success": true,
"data": {
"results": [
{
"id": "result_abc123",
"table": "articles",
"database": "production_db",
"relevanceScore": 0.95,
"matchedColumns": ["title", "content"],
"data": {
"id": 1001,
"title": "MySQL Performance Optimization Guide",
"content": "Complete guide to optimizing MySQL database performance...",
"created_at": "2024-01-15T10:30:00.000Z"
},
"snippet": "... optimizing MySQL database performance ...",
"categories": ["Performance", "MySQL"]
}
],
"categories": [{ "name": "Performance", "count": 1, "confidence": 0.9 }],
"suggestions": [{ "text": "mysql indexing", "score": 0.82, "type": "semantic" }],
"totalCount": 1,
"executionTime": 234,
"page": 1,
"limit": 20
},
"meta": {
"timestamp": "2024-01-15T10:30:00.000Z",
"requestId": "req_abc123",
"version": "0.3.0"
}
}Search Modes
Natural Language Search
Process human-readable queries with automatic optimization.
Example Request:
{
"query": "How to improve database query performance?",
"databases": ["db_uuid_1"],
"searchMode": "natural",
"limit": 10
}Features:
- Automatic query expansion and optimization
- Synonym detection and matching
- Natural language understanding
- Relevance-based ranking
Boolean Search
Use traditional boolean operators for precise control.
Example Request:
{
"query": "(mysql OR postgresql) AND performance AND NOT deprecated",
"databases": ["db_uuid_1"],
"searchMode": "boolean",
"limit": 15
}Supported Operators:
AND- Both terms must be presentOR- Either term can be presentNOT- Term must not be present()- Grouping for complex queries""- Exact phrase matching*- Wildcard matching
Boolean Query Examples:
# Exact phrase
"database optimization"
# Multiple terms (AND implied)
mysql performance tuning
# Explicit boolean operators
(mysql OR postgresql) AND (performance OR optimization)
# Exclude terms
database optimization NOT deprecated
# Wildcards
optim* AND databas*
# Complex grouping
(mysql AND performance) OR (postgresql AND "query optimization")Semantic Search
AI-powered search using embeddings for concept matching.
Example Request:
{
"query": "slow database queries",
"databases": ["db_uuid_1"],
"searchMode": "semantic",
"options": {
"enableAI": true
}
}Features:
- Concept-based matching beyond keywords
- Understanding of context and intent
- Cross-language semantic understanding
- Intelligent query expansion
Search Suggestions
Get Search Suggestions
Retrieve intelligent search suggestions based on query and context.
Endpoint: GET /api/v1/search/suggestions
Query Parameters:
query- Partial query string (required, 1-100 characters)databases- Repeatable:?databases=db1&databases=db2(optional)tables- Repeatable:?tables=articles&tables=docs(optional)
Headers:
Authorization: Bearer <YOUR_API_KEY>Response:
{
"success": true,
"data": {
"suggestions": [
{ "text": "database performance optimization", "score": 0.91, "type": "popular" },
{ "text": "mysql indexing strategies", "score": 0.87, "type": "semantic" }
]
},
"meta": {
"timestamp": "2024-01-15T10:30:00.000Z",
"requestId": "req_abc123",
"version": "0.3.0"
}
}cURL Example:
curl -X GET "http://localhost:3000/api/v1/search/suggestions?query=database%20perf&databases=db_uuid_1&databases=db_uuid_2" \
-H "Authorization: Bearer altus4_sk_live_abc123..."Search Analytics
Analyze Query Performance
Get detailed performance analysis for a search query.
Endpoint: POST /api/v1/search/analyze
Request Body:
{
"query": "database optimization techniques",
"databases": ["db_uuid_1", "db_uuid_2"]
}Response:
{
"success": true,
"data": {
"query": "database optimization techniques",
"recommendations": ["Add FULLTEXT index to articles.content"],
"performance": { "db_uuid_1": { "avgTime": 120 } },
"optimization": [
{ "type": "index", "description": "Create FULLTEXT index on content", "impact": "high" }
]
}
}Search History
Retrieve user's search history with analytics.
Endpoint: GET /api/v1/search/history
Query Parameters:
limit- Number of entries (default: 20, max: 100)offset- Pagination offset (default: 0)
Response:
{
"success": true,
"data": [
{
"id": "search_abc123",
"userId": "user_123",
"query": "database performance optimization",
"database": "db_uuid_1",
"resultCount": 89,
"executionTime": 234,
"timestamp": "2024-01-15T10:30:00.000Z"
}
]
}Search Trends
Get user's search trends and pattern insights.
Endpoint: GET /api/v1/search/trends
No query parameters.
Response:
{
"success": true,
"data": {
"trends": [
{
"date": "2024-01-15",
"searches": 45,
"uniqueQueries": 23
}
],
"summary": {
"totalSearches": 234,
"period": "week",
"topQuery": "database optimization"
}
},
"meta": {
"timestamp": "2024-01-15T10:30:00.000Z",
"requestId": "req_abc123",
"version": "0.3.0"
}
}Code Examples
JavaScript/Node.js
const altus4 = {
apiKey: 'altus4_sk_live_abc123...',
baseUrl: 'http://localhost:3000',
};
// Basic search
const searchResults = async (query, databases) => {
const response = await fetch(`${altus4.baseUrl}/api/v1/search`, {
method: 'POST',
headers: {
Authorization: `Bearer ${altus4.apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
databases,
searchMode: 'natural',
limit: 20,
options: {
enableAI: true,
highlightMatches: true,
},
}),
});
const data = await response.json();
return data.data.results;
};
// Search with advanced options
const advancedSearch = async searchParams => {
const response = await fetch(`${altus4.baseUrl}/api/v1/search`, {
method: 'POST',
headers: {
Authorization: `Bearer ${altus4.apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: searchParams.query,
databases: searchParams.databases,
searchMode: searchParams.mode || 'semantic',
limit: searchParams.limit || 20,
filters: {
tables: searchParams.tables,
dateRange: searchParams.dateRange,
minScore: 0.7,
},
options: {
enableAI: true,
includeSchema: true,
highlightMatches: true,
},
}),
});
return await response.json();
};
// Usage examples
const results = await searchResults('database performance optimization', [
'db_uuid_1',
'db_uuid_2',
]);
const advancedResults = await advancedSearch({
query: 'mysql indexing strategies',
databases: ['db_uuid_1'],
mode: 'semantic',
limit: 15,
tables: ['articles', 'documentation'],
dateRange: {
from: '2024-01-01',
to: '2024-12-31',
},
});Python
import requests
import json
from datetime import datetime, timedelta
class Altus4Search:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'http://localhost:3000'
self.headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
def search(self, query, databases, mode='natural', **kwargs):
"""Execute a search with flexible options"""
payload = {
'query': query,
'databases': databases,
'searchMode': mode,
'limit': kwargs.get('limit', 20),
'offset': kwargs.get('offset', 0)
}
# Add filters if provided
if 'filters' in kwargs:
payload['filters'] = kwargs['filters']
# Add options if provided
if 'options' in kwargs:
payload['options'] = kwargs['options']
response = requests.post(
f'{self.base_url}/api/v1/search',
headers=self.headers,
json=payload
)
return response.json()
def get_suggestions(self, query, databases, limit=5):
"""Get search suggestions"""
params = {
'q': query,
'databases': ','.join(databases),
'limit': limit
}
response = requests.get(
f'{self.base_url}/api/v1/search/suggestions',
headers=self.headers,
params=params
)
return response.json()
def search_history(self, limit=50, days_back=7):
"""Get search history"""
from_date = (datetime.now() - timedelta(days=days_back)).isoformat()
params = {
'limit': limit,
'from': from_date
}
response = requests.get(
f'{self.base_url}/api/v1/search/history',
headers=self.headers,
params=params
)
return response.json()
# Usage
client = Altus4Search('altus4_sk_live_abc123...')
# Basic search
results = client.search(
query='database optimization techniques',
databases=['db_uuid_1'],
mode='semantic'
)
# Advanced search with filters
filtered_results = client.search(
query='mysql performance',
databases=['db_uuid_1', 'db_uuid_2'],
mode='natural',
limit=25,
filters={
'tables': ['articles', 'documentation'],
'dateRange': {
'from': '2024-01-01',
'to': '2024-12-31'
},
'minScore': 0.6
},
options={
'enableAI': True,
'highlightMatches': True,
'includeSchema': True
}
)
# Get suggestions
suggestions = client.get_suggestions(
query='database perf',
databases=['db_uuid_1'],
limit=8
)
print(f"Found {results['data']['summary']['totalResults']} results")
for result in results['data']['results']:
print(f"- {result['content']['title']} (Score: {result['score']})")Search Best Practices
Query Optimization
- Use Specific Terms: More specific queries yield better results
- Leverage Search Modes: Choose the right mode for your use case
- Apply Filters: Use filters to narrow down results effectively
- Cache Results: Enable caching for frequently used queries
Performance Tips
- Limit Results: Use appropriate limits to improve response times
- Batch Databases: Search multiple databases in a single request
- Use Pagination: Implement pagination for large result sets
- Monitor Usage: Track search performance and optimize accordingly
Error Handling
const safeSearch = async (query, databases) => {
try {
const response = await fetch('/api/v1/search', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ query, databases }),
});
if (!response.ok) {
const error = await response.json();
throw new Error(`Search failed: ${error.error.message}`);
}
return await response.json();
} catch (error) {
console.error('Search error:', error.message);
// Fallback to cached results or simplified search
return await getFallbackResults(query);
}
};Next Steps: Database Management | Analytics & Insights