Spaces:
Paused
Paused
Update commons/queryBuilder.js
Browse files- commons/queryBuilder.js +18 -8
commons/queryBuilder.js
CHANGED
|
@@ -1,28 +1,38 @@
|
|
| 1 |
const { convert } = require('lucene-query-generator');
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
module.exports = (args) => {
|
| 4 |
const query = {};
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
if (args.extra) {
|
| 7 |
-
console.log("Extra arguments received:", args.extra); // Add this line
|
| 8 |
Object.keys(args.extra).forEach((key) => {
|
| 9 |
let value = args.extra[key];
|
| 10 |
if (typeof value !== 'string') value = String(value);
|
| 11 |
-
if (value && value.trim().length > 0)
|
|
|
|
|
|
|
| 12 |
});
|
| 13 |
}
|
| 14 |
|
| 15 |
-
// Log the
|
| 16 |
-
console.log("Query constructed:", query);
|
| 17 |
|
| 18 |
// Generate the Lucene query using a field-focused structure
|
| 19 |
const formattedQuery = convert({
|
| 20 |
-
title: query.genre,
|
| 21 |
-
subject: query.genre,
|
| 22 |
-
description: query.genre,
|
| 23 |
-
collection: query.genre,
|
| 24 |
});
|
| 25 |
|
|
|
|
|
|
|
| 26 |
if (formattedQuery) {
|
| 27 |
return `(${formattedQuery}) AND !collection:(podcasts OR radio OR uspto)`;
|
| 28 |
}
|
|
|
|
| 1 |
const { convert } = require('lucene-query-generator');
|
| 2 |
|
| 3 |
+
/**
|
| 4 |
+
* Builds a complex Lucene query formatted for Archive.org based on arguments.
|
| 5 |
+
* Ensures all query terms are properly formatted as strings.
|
| 6 |
+
*/
|
| 7 |
module.exports = (args) => {
|
| 8 |
const query = {};
|
| 9 |
|
| 10 |
+
// Log the incoming args to see if we're getting the correct structure
|
| 11 |
+
console.log("Incoming arguments for queryBuilder:", args);
|
| 12 |
+
|
| 13 |
if (args.extra) {
|
|
|
|
| 14 |
Object.keys(args.extra).forEach((key) => {
|
| 15 |
let value = args.extra[key];
|
| 16 |
if (typeof value !== 'string') value = String(value);
|
| 17 |
+
if (value && value.trim().length > 0) {
|
| 18 |
+
query[key] = value;
|
| 19 |
+
}
|
| 20 |
});
|
| 21 |
}
|
| 22 |
|
| 23 |
+
// Log the constructed query
|
| 24 |
+
console.log("Query constructed:", query);
|
| 25 |
|
| 26 |
// Generate the Lucene query using a field-focused structure
|
| 27 |
const formattedQuery = convert({
|
| 28 |
+
title: query.genre || '', // Ensure we handle the case if genre is not present
|
| 29 |
+
subject: query.genre || '',
|
| 30 |
+
description: query.genre || '',
|
| 31 |
+
collection: query.genre || '',
|
| 32 |
});
|
| 33 |
|
| 34 |
+
console.log("Formatted Lucene Query:", formattedQuery); // Debugging: log the formatted query
|
| 35 |
+
|
| 36 |
if (formattedQuery) {
|
| 37 |
return `(${formattedQuery}) AND !collection:(podcasts OR radio OR uspto)`;
|
| 38 |
}
|