Add description to items where available, use it in search index.

This commit is contained in:
Mario Zechner 2023-06-17 20:54:45 +02:00
parent ad01cc0658
commit 898fa44ff1
12 changed files with 14 additions and 2 deletions

View File

@ -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}`);
}

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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 }],

View File

@ -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,

View File

@ -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,

View File

@ -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 }],

View File

@ -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,

View File

@ -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,