mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-09-22 00:00:59 +02:00
Add description to items where available, use it in search index.
This commit is contained in:
parent
ad01cc0658
commit
898fa44ff1
|
@ -57,7 +57,7 @@ exports.index = (items) => {
|
|||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
const tokens = this.tokenize(item.name);
|
||||
const tokens = this.tokenize(item.name + " " + (item.description ?? ""));
|
||||
const doc = {
|
||||
id: item.store + item.id,
|
||||
body: item.name,
|
||||
|
@ -93,6 +93,7 @@ exports.index = (items) => {
|
|||
index.docs.push(doc);
|
||||
index.totalDocLength += tokens.length;
|
||||
index.averageDocLength = index.totalDocLength / index.docs.length;
|
||||
if (i % 1000 == 0) console.log(`indexed ${i}/${items.length}`);
|
||||
}
|
||||
|
||||
var keys = Object.keys(index.words);
|
||||
|
@ -161,7 +162,7 @@ if (require.main === module) {
|
|||
while (true) {
|
||||
const query = readline.question("> ");
|
||||
const result = exports.search(index, query);
|
||||
for (let i = 0; i < Math.min(result.length, 20); i++) {
|
||||
for (let i = 0; i < Math.min(result.length, 50); i++) {
|
||||
const doc = result[i];
|
||||
console.log(`${doc.score} ${doc.body}`);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.data.articleId,
|
||||
name: item.data.name,
|
||||
description: item.data.description ?? "",
|
||||
price: item.data.price.final,
|
||||
priceHistory: [{ date: today, price: item.data.price.final }],
|
||||
isWeighted: item.data.isWeightArticle,
|
||||
|
|
|
@ -17,6 +17,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.gtin,
|
||||
name: `${item.brandName} ${item.title}`,
|
||||
// description: "", not available
|
||||
price: item.price.value,
|
||||
priceHistory: [{ date: today, price: item.price.value }],
|
||||
unit,
|
||||
|
|
|
@ -18,6 +18,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: "" + item.gtin,
|
||||
name: `${item.brandName} ${item.title}`,
|
||||
// description: "", not available
|
||||
price: item.price.value,
|
||||
priceHistory: [{ date: today, price: item.price.value }],
|
||||
unit,
|
||||
|
|
|
@ -17,6 +17,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.ProductID,
|
||||
name,
|
||||
// description: "", not available
|
||||
price: item.Price,
|
||||
priceHistory: [{ date: today, price: item.Price }],
|
||||
isWeighted: item.IsBulk,
|
||||
|
|
|
@ -40,6 +40,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.productId,
|
||||
name: `${item.keyfacts?.supplementalDescription?.concat(" ") ?? ""}${item.fullTitle}`,
|
||||
description: item.keyfacts?.description ?? "",
|
||||
price: item.price.price,
|
||||
priceHistory: [{ date: today, price: item.price.price }],
|
||||
unit,
|
||||
|
|
|
@ -31,6 +31,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.code,
|
||||
name: item.name[0],
|
||||
description: item.mixins?.productCustomAttributes?.longDescription ?? "",
|
||||
isWeighted,
|
||||
price: isWeighted ? item.prices[0].effectiveAmount : item.prices[0].presentationPrice.effectiveAmount,
|
||||
priceHistory: [{ date: today, price: item.prices[0].presentationPrice.effectiveAmount }],
|
||||
|
|
|
@ -19,6 +19,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.productId,
|
||||
name: item.name,
|
||||
// description: "", not available
|
||||
price: item.price.regular.value / 100,
|
||||
priceHistory: [{ date: today, price: item.price.regular.value / 100 }],
|
||||
isWeighted: item.isWeightArticle,
|
||||
|
|
|
@ -51,6 +51,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
// description: "", not available
|
||||
price,
|
||||
priceHistory: [{ date: today, price }],
|
||||
isWeighted: false,
|
||||
|
|
|
@ -62,6 +62,7 @@ exports.getCanonical = function (item, today) {
|
|||
return utils.convertUnit(
|
||||
{
|
||||
id: item.masterValues["code-internal"],
|
||||
// description: "", not available
|
||||
name,
|
||||
price,
|
||||
priceHistory: [{ date: today, price }],
|
||||
|
|
|
@ -55,6 +55,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.masterValues["product-number"],
|
||||
name: item.masterValues.title + " " + (item.masterValues["short-description"] ?? item.masterValues.name),
|
||||
description: item.masterValues["marketing-text"] ?? "",
|
||||
price,
|
||||
priceHistory: [{ date: today, price }],
|
||||
unit,
|
||||
|
|
|
@ -12,6 +12,7 @@ exports.getCanonical = function (item, today) {
|
|||
{
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
// description: "", not available
|
||||
price: item.price,
|
||||
priceHistory: [{ date: today, price: item.price }],
|
||||
quantity,
|
||||
|
|
Loading…
Reference in New Issue
Block a user