Skip to content

Commit d6649fe

Browse files
authored
Merge pull request elizaOS#1494 from chandiniv1/chandini/websearch-plugin-docs
feat: add readme for websearch plugin
2 parents 70d421e + 7c0d906 commit d6649fe

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

packages/plugin-web-search/Readme.md

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Plugin Web Search
2+
3+
## Overview
4+
5+
The Web Search Plugin enables powerful and customizable web search capabilities, offering flexibility and ease of integration for modern applications.
6+
7+
## Features
8+
9+
- Efficient search query handling.
10+
- Configurable options for advanced customization.
11+
- Optimized for performance and scalability.
12+
13+
## Handlers
14+
15+
### `search`
16+
17+
The `search` handler executes web search queries with specified parameters, returning results in a structured format.
18+
19+
#### Usage
20+
21+
```typescript
22+
import { WebSearch } from 'web-search-plugin';
23+
24+
const search = new WebSearch({
25+
apiEndpoint: 'https://api.example.com/search',
26+
timeout: 5000,
27+
});
28+
29+
try {
30+
const results = await search.query('example query', {
31+
limit: 10,
32+
sortBy: 'relevance',
33+
});
34+
console.log('Search Results:', results);
35+
} catch (error) {
36+
console.error('Search failed:', error);
37+
}
38+
```
39+
40+
#### Features
41+
42+
- **Query Customization**: Specify query parameters such as `limit` and `sortBy`.
43+
- **Error Handling**: Handles common search errors gracefully.
44+
45+
## Configuration
46+
47+
### Environment Variables
48+
49+
Set the following environment variables for optimal performance:
50+
51+
| Variable Name | Description |
52+
| ---------------- | --------------------------------- |
53+
| `API_ENDPOINT` | URL for the search API endpoint. |
54+
| `SEARCH_TIMEOUT` | Timeout duration in milliseconds. |
55+
56+
Example `.env` file:
57+
58+
```env
59+
API_ENDPOINT=https://api.example.com/search
60+
SEARCH_TIMEOUT=5000
61+
```
62+
63+
### TypeScript Configuration
64+
65+
Ensure your `tsconfig.json` is properly configured:
66+
67+
```json
68+
{
69+
"compilerOptions": {
70+
"target": "ESNext",
71+
"module": "CommonJS",
72+
"strict": true,
73+
"esModuleInterop": true,
74+
"skipLibCheck": true
75+
}
76+
}
77+
```
78+
79+
## Example Workflow
80+
81+
Streamline your search operations with the following example:
82+
83+
```typescript
84+
import { WebSearch } from 'web-search-plugin';
85+
86+
const search = new WebSearch({ apiEndpoint: 'https://api.example.com/search' });
87+
88+
(async () => {
89+
try {
90+
// Execute a search query
91+
const results = await search.query('example', { limit: 5 });
92+
console.log('Search Results:', results);
93+
} catch (error) {
94+
console.error('Error executing search:', error);
95+
}
96+
})();
97+
```
98+
99+
## Local Testing
100+
101+
To test locally, you can set up a mock server for the API endpoint:
102+
103+
1. Install `json-server`:
104+
105+
```bash
106+
npm install -g json-server
107+
```
108+
109+
2. Create a `db.json` file with mock search data.
110+
111+
3. Start the mock server:
112+
113+
```bash
114+
json-server --watch db.json --port 3000
115+
```
116+
117+
4. Update your `.env` file:
118+
```env
119+
API_ENDPOINT=http://localhost:3000
120+
```
121+
122+
## Common Issues
123+
124+
### "API endpoint not defined"
125+
126+
- Ensure the `API_ENDPOINT` is set in your environment variables.
127+
128+
### "Search query timeout"
129+
130+
- Increase the `SEARCH_TIMEOUT` value in the configuration.
131+
132+
## Dependencies
133+
134+
This plugin relies on the following:
135+
136+
- `axios` for HTTP requests.
137+
- `dotenv` for managing environment variables.
138+
139+
## Development Guide
140+
141+
### Setup
142+
143+
1. Clone the repository:
144+
145+
```bash
146+
git clone https://github.com/your-repo/web-search-plugin.git
147+
```
148+
149+
2. Install dependencies:
150+
```bash
151+
npm install
152+
```
153+
154+
### Testing
155+
156+
Run tests with:
157+
158+
```bash
159+
npm test
160+
```
161+
162+
### Contribution Guidelines
163+
164+
- Fork the repository.
165+
- Create a feature branch.
166+
- Submit a pull request with a clear description.
167+
168+
### Security Best Practices
169+
170+
- Validate user inputs to prevent injection attacks.
171+
- Use HTTPS for secure API communication.
172+
173+
## Performance Optimization
174+
175+
- Use caching for frequently queried terms.
176+
- Optimize query parameters for faster responses.
177+
178+
---
179+
180+
This documentation aims to streamline onboarding, reduce support queries, and enable faster adoption of the Web Search Plugin.

0 commit comments

Comments
 (0)