Skip to content

Commit bc271d0

Browse files
committed
Add SEARCH_TERM_MIN_LENGTH configuration for minimum search term length
- Add SEARCH_TERM_MIN_LENGTH environment variable (default: 0) - Implement minimum length validation in search functionality - Update Docker configurations and documentation - Add changelog entry for version 1.0.7
1 parent 3ba8292 commit bc271d0

8 files changed

Lines changed: 56 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to **takeCode** will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.7] - 2025-01-09
9+
10+
### Added
11+
- **Minimum Search Term Length**: Added `SEARCH_TERM_MIN_LENGTH` environment variable to set minimum character requirement for search terms (default: 0, no minimum)
12+
13+
### Technical Details
14+
- Added configurable minimum search term length with validation and user feedback
15+
- Updated configuration system to support new environment variable across all deployment methods
16+
- Enhanced search input handler to enforce minimum length requirements
17+
818
## [1.0.6] - 2025-09-20
919

1020
### Fixed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ environment:
131131
# No environment variable needed
132132
```
133133

134+
#### SEARCH_TERM_MIN_LENGTH
135+
136+
Controls the minimum length of search terms required to perform a search.
137+
138+
- **Default**: `1` (match from first character on)
139+
- **Range**: `1` to `9007199254740991` (JavaScript's `Number.MAX_SAFE_INTEGER`)
140+
- **Behavior**: If the search term is shorter than this search will not be executed
141+
142+
**Examples:**
143+
144+
```yaml
145+
# Require at least 2 characters for search
146+
environment:
147+
- SEARCH_TERM_MIN_LENGTH=2
148+
149+
# Require at least 3 characters for search
150+
environment:
151+
- SEARCH_TERM_MIN_LENGTH=3
152+
153+
# No minimum length (default)
154+
# No environment variable needed
155+
```
156+
134157
### Manual Docker Run
135158

136159
```bash

docker-compose-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ services:
88
- ./db.json:/data/db.json:ro
99
environment:
1010
- SEARCH_HIGHLIGHT_LIMIT=10
11+
- SEARCH_TERM_MIN_LENGTH=2
1112
restart: unless-stopped

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ services:
88
- ./db.json:/data/db.json:ro
99
#environment:
1010
# - SEARCH_HIGHLIGHT_LIMIT=3
11+
# - SEARCH_TERM_MIN_LENGTH=1
1112
restart: unless-stopped

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# Substitute environment variables in index.html
3-
envsubst '${SEARCH_HIGHLIGHT_LIMIT}' < /usr/share/nginx/html/index.html > /usr/share/nginx/html/index.html.tmp
3+
envsubst '${SEARCH_HIGHLIGHT_LIMIT} ${SEARCH_TERM_MIN_LENGTH}' < /usr/share/nginx/html/index.html > /usr/share/nginx/html/index.html.tmp
44
mv /usr/share/nginx/html/index.html.tmp /usr/share/nginx/html/index.html
55

66
# Start nginx

nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Enable environment variable access
22
env SEARCH_HIGHLIGHT_LIMIT;
3+
env SEARCH_TERM_MIN_LENGTH;
34

45
events {
56
worker_connections 1024;

public/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ <h1 class="text-2xl font-bold truncate">takeCode</h1>
7070
<script>
7171
// Set global config from environment variables
7272
window.TAKECODE_CONFIG = {
73-
SEARCH_HIGHLIGHT_LIMIT: parseInt('${SEARCH_HIGHLIGHT_LIMIT}') || 3
73+
SEARCH_HIGHLIGHT_LIMIT: parseInt('${SEARCH_HIGHLIGHT_LIMIT}') || 3,
74+
SEARCH_TERM_MIN_LENGTH: Math.max(1, parseInt('${SEARCH_TERM_MIN_LENGTH}') || 1)
7475
};
7576

7677
// Keyboard shortcuts

public/js/app.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ document.addEventListener('DOMContentLoaded', () => {
220220

221221
const query = e.target.value;
222222
const activeSnippets = dbData.snippets.filter(s => !s.isDeleted);
223+
const minLength = window.TAKECODE_CONFIG?.SEARCH_TERM_MIN_LENGTH ?? 1;
223224

224225
if (query.trim() === '') {
225226
// No search query - show all snippets with first tab active and no highlighting
@@ -236,6 +237,22 @@ document.addEventListener('DOMContentLoaded', () => {
236237

237238
// Hide search info bar when no search is active
238239
searchInfoBar.classList.add('hidden');
240+
} else if (query.trim().length < minLength) {
241+
// Search term too short - show all snippets without highlighting
242+
currentSnippets = activeSnippets.map(snippet => ({
243+
...snippet,
244+
activeTabIndex: 0, // Always show first tab when no search
245+
highlightedContent: snippet.content.map(content => ({
246+
...content,
247+
highlightedValue: content.value // No highlighting
248+
})),
249+
highlightedName: snippet.name,
250+
highlightedDescription: snippet.description
251+
}));
252+
253+
// Show message about minimum length
254+
searchInfoBar.innerHTML = `Search term too short (minimum ${minLength} characters)`;
255+
searchInfoBar.classList.remove('hidden');
239256
} else {
240257
// Filter snippets and determine which tab should be active
241258
const filteredSnippets = activeSnippets.filter(snippet => {

0 commit comments

Comments
 (0)