Spaces:
Paused
Paused
Update commons/queryBuilder.js
Browse files- commons/queryBuilder.js +13 -21
commons/queryBuilder.js
CHANGED
|
@@ -1,39 +1,31 @@
|
|
| 1 |
const { convert } = require('lucene-query-generator');
|
| 2 |
|
| 3 |
/**
|
| 4 |
-
* Builds
|
| 5 |
* Ensures all query terms are properly formatted as strings.
|
| 6 |
*/
|
| 7 |
module.exports = (args) => {
|
| 8 |
const query = {};
|
| 9 |
|
| 10 |
if (args.extra) {
|
| 11 |
-
// Process `extra` parameters, converting values to strings if necessary
|
| 12 |
Object.keys(args.extra).forEach((key) => {
|
| 13 |
let value = args.extra[key];
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if (typeof value !== 'string') {
|
| 17 |
-
value = String(value);
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
// Add non-empty strings to the query
|
| 21 |
-
if (value && value.trim().length > 0) {
|
| 22 |
-
query[key] = value;
|
| 23 |
-
}
|
| 24 |
});
|
| 25 |
}
|
| 26 |
|
| 27 |
-
// Generate the Lucene query
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
-
// Return an empty string if no query was generated
|
| 38 |
return '';
|
| 39 |
};
|
|
|
|
| 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 |
if (args.extra) {
|
|
|
|
| 11 |
Object.keys(args.extra).forEach((key) => {
|
| 12 |
let value = args.extra[key];
|
| 13 |
+
if (typeof value !== 'string') value = String(value);
|
| 14 |
+
if (value && value.trim().length > 0) query[key] = value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
});
|
| 16 |
}
|
| 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 |
}
|
| 29 |
|
|
|
|
| 30 |
return '';
|
| 31 |
};
|