Skip to content

Commit 07f2be9

Browse files
Merge pull request #162 from CodeForPhilly/feat/zbl-enahancedsearch
Feat/zbl enahancedsearch
2 parents a786414 + d1df800 commit 07f2be9

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

lib/db.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ const {
88
MONGODB_DATABASE,
99
MONGODB_DOCKER_PORT,
1010
// Traditional environment variables
11-
DB_HOST='localhost',
11+
DB_HOST,
1212
DB_PORT=27017,
1313
DB_NAME='pa-wildflower-selector',
1414
DB_USER,
1515
DB_PASSWORD
1616
} = process.env;
1717

1818
// Use Docker variables if available, fall back to traditional ones
19-
const host = DB_HOST || 'mongodb'; // Use 'mongodb' as default in Docker
19+
// Default to 'mongodb' (Docker mode) unless DB_HOST is explicitly 'localhost'
20+
const host = DB_HOST === 'localhost' ? 'localhost' : (DB_HOST || 'mongodb');
2021
const port = MONGODB_DOCKER_PORT || DB_PORT;
2122
const dbName = MONGODB_DATABASE || DB_NAME;
2223
const user = MONGODB_USER || DB_USER;

lib/embeddings.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
const { pipeline } = require('@xenova/transformers');
2-
3-
// Cache the model to avoid reloading
1+
// Cache the transformers module and model to avoid reloading
2+
let transformersModule = null;
43
let embeddingModel = null;
54

5+
/**
6+
* Get the transformers module using dynamic import (required for ES modules)
7+
*/
8+
async function getTransformersModule() {
9+
if (!transformersModule) {
10+
transformersModule = await import('@xenova/transformers');
11+
}
12+
return transformersModule;
13+
}
14+
615
/**
716
* Initialize the embedding model
817
* Uses a lightweight sentence transformer model optimized for search
918
*/
1019
async function getEmbeddingModel() {
1120
if (!embeddingModel) {
1221
console.log('Loading embedding model...');
22+
const { pipeline } = await getTransformersModule();
1323
embeddingModel = await pipeline(
1424
'feature-extraction',
1525
'Xenova/all-MiniLM-L6-v2' // Lightweight model, ~80MB, good for semantic search

scripts/check-mongodb.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ const {
1616
MONGODB_DATABASE,
1717
MONGODB_DOCKER_PORT,
1818
// Traditional environment variables
19-
DB_HOST = 'localhost',
19+
DB_HOST,
2020
DB_PORT = 27017,
2121
DB_NAME = 'pa-wildflower-selector',
2222
DB_USER,
2323
DB_PASSWORD
2424
} = process.env;
2525

2626
// Use Docker variables if available, fall back to traditional ones
27-
const host = DB_HOST || 'mongodb'; // Use 'mongodb' as default in Docker
27+
// Default to 'mongodb' (Docker mode) unless DB_HOST is explicitly 'localhost'
28+
const host = DB_HOST === 'localhost' ? 'localhost' : (DB_HOST || 'mongodb');
2829
const port = MONGODB_DOCKER_PORT || DB_PORT;
2930
const dbName = MONGODB_DATABASE || DB_NAME;
3031
const user = MONGODB_USER || DB_USER;

scripts/dev-setup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const requiredEnvVars = [
2020

2121
// MongoDB connection variables
2222
const {
23-
DB_HOST = 'localhost',
23+
DB_HOST,
2424
MONGODB_USER,
2525
MONGODB_PASSWORD,
2626
MONGODB_DATABASE,
@@ -31,8 +31,8 @@ const {
3131
DB_PASSWORD
3232
} = process.env;
3333

34-
// Detect mode
35-
const host = DB_HOST || 'mongodb';
34+
// Detect mode - default to Docker unless explicitly localhost
35+
const host = DB_HOST === 'localhost' ? 'localhost' : (DB_HOST || 'mongodb');
3636
const isDockerMode = host === 'mongodb';
3737
const mode = isDockerMode ? 'Docker' : 'Local';
3838

scripts/sync-down.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const {
2222
LINODE_BUCKET_NAME,
2323
LINODE_ENDPOINT_URL = 'https://us-east-1.linodeobjects.com',
2424
// MongoDB connection settings
25-
DB_HOST = 'localhost',
25+
DB_HOST,
2626
DB_PORT = 27017,
2727
MONGODB_USER,
2828
MONGODB_PASSWORD,
@@ -40,7 +40,8 @@ if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !LINODE_BUCKET_NAME) {
4040
}
4141

4242
// MongoDB connection settings
43-
const host = DB_HOST;
43+
// Default to 'mongodb' (Docker mode) unless DB_HOST is explicitly 'localhost'
44+
const host = DB_HOST === 'localhost' ? 'localhost' : (DB_HOST || 'mongodb');
4445
const port = MONGODB_DOCKER_PORT || DB_PORT;
4546
const user = MONGODB_USER || DB_USER;
4647
const password = MONGODB_PASSWORD || DB_PASSWORD;

0 commit comments

Comments
 (0)