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++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
const item = items[i];
|
const item = items[i];
|
||||||
const tokens = this.tokenize(item.name);
|
const tokens = this.tokenize(item.name + " " + (item.description ?? ""));
|
||||||
const doc = {
|
const doc = {
|
||||||
id: item.store + item.id,
|
id: item.store + item.id,
|
||||||
body: item.name,
|
body: item.name,
|
||||||
|
@ -93,6 +93,7 @@ exports.index = (items) => {
|
||||||
index.docs.push(doc);
|
index.docs.push(doc);
|
||||||
index.totalDocLength += tokens.length;
|
index.totalDocLength += tokens.length;
|
||||||
index.averageDocLength = index.totalDocLength / index.docs.length;
|
index.averageDocLength = index.totalDocLength / index.docs.length;
|
||||||
|
if (i % 1000 == 0) console.log(`indexed ${i}/${items.length}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys = Object.keys(index.words);
|
var keys = Object.keys(index.words);
|
||||||
|
@ -161,7 +162,7 @@ if (require.main === module) {
|
||||||
while (true) {
|
while (true) {
|
||||||
const query = readline.question("> ");
|
const query = readline.question("> ");
|
||||||
const result = exports.search(index, query);
|
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];
|
const doc = result[i];
|
||||||
console.log(`${doc.score} ${doc.body}`);
|
console.log(`${doc.score} ${doc.body}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.data.articleId,
|
id: item.data.articleId,
|
||||||
name: item.data.name,
|
name: item.data.name,
|
||||||
|
description: item.data.description ?? "",
|
||||||
price: item.data.price.final,
|
price: item.data.price.final,
|
||||||
priceHistory: [{ date: today, price: item.data.price.final }],
|
priceHistory: [{ date: today, price: item.data.price.final }],
|
||||||
isWeighted: item.data.isWeightArticle,
|
isWeighted: item.data.isWeightArticle,
|
||||||
|
|
|
@ -17,6 +17,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.gtin,
|
id: item.gtin,
|
||||||
name: `${item.brandName} ${item.title}`,
|
name: `${item.brandName} ${item.title}`,
|
||||||
|
// description: "", not available
|
||||||
price: item.price.value,
|
price: item.price.value,
|
||||||
priceHistory: [{ date: today, price: item.price.value }],
|
priceHistory: [{ date: today, price: item.price.value }],
|
||||||
unit,
|
unit,
|
||||||
|
|
|
@ -18,6 +18,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: "" + item.gtin,
|
id: "" + item.gtin,
|
||||||
name: `${item.brandName} ${item.title}`,
|
name: `${item.brandName} ${item.title}`,
|
||||||
|
// description: "", not available
|
||||||
price: item.price.value,
|
price: item.price.value,
|
||||||
priceHistory: [{ date: today, price: item.price.value }],
|
priceHistory: [{ date: today, price: item.price.value }],
|
||||||
unit,
|
unit,
|
||||||
|
|
|
@ -17,6 +17,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.ProductID,
|
id: item.ProductID,
|
||||||
name,
|
name,
|
||||||
|
// description: "", not available
|
||||||
price: item.Price,
|
price: item.Price,
|
||||||
priceHistory: [{ date: today, price: item.Price }],
|
priceHistory: [{ date: today, price: item.Price }],
|
||||||
isWeighted: item.IsBulk,
|
isWeighted: item.IsBulk,
|
||||||
|
|
|
@ -40,6 +40,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.productId,
|
id: item.productId,
|
||||||
name: `${item.keyfacts?.supplementalDescription?.concat(" ") ?? ""}${item.fullTitle}`,
|
name: `${item.keyfacts?.supplementalDescription?.concat(" ") ?? ""}${item.fullTitle}`,
|
||||||
|
description: item.keyfacts?.description ?? "",
|
||||||
price: item.price.price,
|
price: item.price.price,
|
||||||
priceHistory: [{ date: today, price: item.price.price }],
|
priceHistory: [{ date: today, price: item.price.price }],
|
||||||
unit,
|
unit,
|
||||||
|
|
|
@ -31,6 +31,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.code,
|
id: item.code,
|
||||||
name: item.name[0],
|
name: item.name[0],
|
||||||
|
description: item.mixins?.productCustomAttributes?.longDescription ?? "",
|
||||||
isWeighted,
|
isWeighted,
|
||||||
price: isWeighted ? item.prices[0].effectiveAmount : item.prices[0].presentationPrice.effectiveAmount,
|
price: isWeighted ? item.prices[0].effectiveAmount : item.prices[0].presentationPrice.effectiveAmount,
|
||||||
priceHistory: [{ date: today, price: 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,
|
id: item.productId,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
// description: "", not available
|
||||||
price: item.price.regular.value / 100,
|
price: item.price.regular.value / 100,
|
||||||
priceHistory: [{ date: today, price: item.price.regular.value / 100 }],
|
priceHistory: [{ date: today, price: item.price.regular.value / 100 }],
|
||||||
isWeighted: item.isWeightArticle,
|
isWeighted: item.isWeightArticle,
|
||||||
|
|
|
@ -51,6 +51,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
// description: "", not available
|
||||||
price,
|
price,
|
||||||
priceHistory: [{ date: today, price }],
|
priceHistory: [{ date: today, price }],
|
||||||
isWeighted: false,
|
isWeighted: false,
|
||||||
|
|
|
@ -62,6 +62,7 @@ exports.getCanonical = function (item, today) {
|
||||||
return utils.convertUnit(
|
return utils.convertUnit(
|
||||||
{
|
{
|
||||||
id: item.masterValues["code-internal"],
|
id: item.masterValues["code-internal"],
|
||||||
|
// description: "", not available
|
||||||
name,
|
name,
|
||||||
price,
|
price,
|
||||||
priceHistory: [{ date: today, price }],
|
priceHistory: [{ date: today, price }],
|
||||||
|
|
|
@ -55,6 +55,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.masterValues["product-number"],
|
id: item.masterValues["product-number"],
|
||||||
name: item.masterValues.title + " " + (item.masterValues["short-description"] ?? item.masterValues.name),
|
name: item.masterValues.title + " " + (item.masterValues["short-description"] ?? item.masterValues.name),
|
||||||
|
description: item.masterValues["marketing-text"] ?? "",
|
||||||
price,
|
price,
|
||||||
priceHistory: [{ date: today, price }],
|
priceHistory: [{ date: today, price }],
|
||||||
unit,
|
unit,
|
||||||
|
|
|
@ -12,6 +12,7 @@ exports.getCanonical = function (item, today) {
|
||||||
{
|
{
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
// description: "", not available
|
||||||
price: item.price,
|
price: item.price,
|
||||||
priceHistory: [{ date: today, price: item.price }],
|
priceHistory: [{ date: today, price: item.price }],
|
||||||
quantity,
|
quantity,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user