Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-1454: add relevance score to Product/Category #745

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/VirtoCommerce.CatalogModule.Core/Model/CatalogProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
using VirtoCommerce.CoreModule.Core.Seo;
using VirtoCommerce.ExportModule.Core.Model;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.SearchModule.Core.Model;

namespace VirtoCommerce.CatalogModule.Core.Model
{
public class CatalogProduct : AuditableEntity, IHasLinks, ISeoSupport, IHasOutlines, IHasDimension, IHasAssociations, IHasProperties, IHasImages, IHasAssets, IInheritable, IHasTaxType, IHasName, IHasOuterId, IExportable, ICopyable, IHasCategoryId, IHasExcludedProperties
public class CatalogProduct : AuditableEntity, IHasLinks, ISeoSupport, IHasOutlines, IHasDimension, IHasAssociations, IHasProperties, IHasImages, IHasAssets, IInheritable, IHasTaxType, IHasName, IHasOuterId, IExportable, ICopyable, IHasCategoryId, IHasExcludedProperties, IHasRelevanceScore
{
/// <summary>
/// The type of product. Can be "Physical", "Digital", etc.
Expand Down Expand Up @@ -452,6 +453,8 @@ public bool ParentCategoryIsActive
}
}

public double? RelevanceScore { get; set; }

public virtual object GetCopy()
{
var result = this.CloneTyped();
Expand Down
5 changes: 4 additions & 1 deletion src/VirtoCommerce.CatalogModule.Core/Model/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
using VirtoCommerce.CoreModule.Core.Seo;
using VirtoCommerce.ExportModule.Core.Model;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.SearchModule.Core.Model;

namespace VirtoCommerce.CatalogModule.Core.Model
{
public class Category : AuditableEntity, IHasLinks, ISeoSupport, IHasOutlines, IHasImages, IHasProperties, IHasTaxType, IHasName, IHasOuterId, IExportable, IHasExcludedProperties
public class Category : AuditableEntity, IHasLinks, ISeoSupport, IHasOutlines, IHasImages, IHasProperties, IHasTaxType, IHasName, IHasOuterId, IExportable, IHasExcludedProperties, IHasRelevanceScore
{
public Category()
{
Expand Down Expand Up @@ -179,6 +180,8 @@ public bool ParentIsActive
}
}

public double? RelevanceScore { get; set; }

public virtual void Move(string catalogId, string categoryId)
{
CatalogId = catalogId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.Linq;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.SearchModule.Core.Model;

namespace VirtoCommerce.CatalogModule.Core.Model.ListEntry
{
/// <summary>
/// Category ListEntry record.
/// </summary>
public class CategoryListEntry : ListEntryBase
public class CategoryListEntry : ListEntryBase, IHasRelevanceScore
{
public const string TypeName = "category";

public double? RelevanceScore { get; set; }

public override ListEntryBase FromModel(AuditableEntity entity)
{
base.FromModel(entity);
Expand All @@ -23,6 +26,7 @@ public override ListEntryBase FromModel(AuditableEntity entity)
IsActive = category.IsActive;
Links = category.Links;
CatalogId = category.CatalogId;
RelevanceScore = category.RelevanceScore;

if (!category.Outlines.IsNullOrEmpty())
{
Expand All @@ -31,6 +35,7 @@ public override ListEntryBase FromModel(AuditableEntity entity)
Path = category.Outlines.First().Items.Select(x => x.Name).ToList();
}
}

return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
using System.Linq;
using VirtoCommerce.CoreModule.Core.Outlines;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.SearchModule.Core.Model;

namespace VirtoCommerce.CatalogModule.Core.Model.ListEntry
{
/// <summary>
/// Product ListEntry record.
/// </summary>
public class ProductListEntry : ListEntryBase, IHasOutlines
public class ProductListEntry : ListEntryBase, IHasOutlines, IHasRelevanceScore
{
public const string TypeName = "product";
public string ProductType { get; set; }
public IList<Outline> Outlines { get; set; }
public double? RelevanceScore { get; set; }

public override ListEntryBase FromModel(AuditableEntity entity)
{
Expand All @@ -28,6 +30,7 @@ public override ListEntryBase FromModel(AuditableEntity entity)
ProductType = product.ProductType;
Links = product.Links;
CatalogId = product.CatalogId;
RelevanceScore = product.RelevanceScore;

if (!product.Outlines.IsNullOrEmpty())
{
Expand All @@ -36,8 +39,8 @@ public override ListEntryBase FromModel(AuditableEntity entity)
Path = product.Outlines.FirstOrDefault().Items.Select(x => x.Name).ToList();
Outlines = product.Outlines;
}

}

return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.ExportModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.851.0" />
<PackageReference Include="VirtoCommerce.SearchModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.SearchModule.Core" Version="3.803.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using VirtoCommerce.CatalogModule.Core.Model.Search;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Settings;
using VirtoCommerce.SearchModule.Core.Extensions;
using VirtoCommerce.SearchModule.Core.Model;
using VirtoCommerce.SearchModule.Core.Services;

Expand Down Expand Up @@ -89,7 +90,20 @@ protected virtual async Task<TItem[]> ConvertDocuments(IList<SearchDocument> doc
ReduceSearchResults(itemsMap.Values.Where(v => v != null), criteria);

// Preserve original sorting order
result = documents.Select(doc => itemsMap[doc.Id.ToString()]).Where(x => x != null).ToArray();
result = documents
.Select(doc =>
{
var item = itemsMap.TryGetValue(doc.Id, out var value) ? value : null;

if (item is IHasRelevanceScore hasRelevanceScore)
{
hasRelevanceScore.RelevanceScore = doc.GetRelevanceScore();
}

return item;
})
.Where(x => x != null)
.ToArray();
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.CatalogModule.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<dependency id="VirtoCommerce.BulkActionsModule" version="3.800.0" optional="true" />
<dependency id="VirtoCommerce.Core" version="3.800.0" />
<dependency id="VirtoCommerce.Export" version="3.800.0" optional="true" />
<dependency id="VirtoCommerce.Search" version="3.800.0" />
<dependency id="VirtoCommerce.Search" version="3.803.0" />
<dependency id="VirtoCommerce.Store" version="3.800.0" />
</dependencies>

Expand Down
Loading