Skip to content

Commit

Permalink
VCST-1901: Add descriptions and SEO to the Content field (#748)
Browse files Browse the repository at this point in the history
feat: Extends Content field with search by descriptions and seo.
  • Loading branch information
OlegoO authored Oct 21, 2024
1 parent 786015b commit 8d20c8b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.808.0" />
<PackageReference Include="VirtoCommerce.ExportModule.Core" Version="3.803.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.853.0" />
<PackageReference Include="VirtoCommerce.SearchModule.Core" Version="3.804.0" />
<PackageReference Include="VirtoCommerce.SearchModule.Core" Version="3.805.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using VirtoCommerce.CatalogModule.Core.Model.Search;
using VirtoCommerce.CatalogModule.Core.Search;
using VirtoCommerce.CoreModule.Core.Outlines;
using VirtoCommerce.CoreModule.Core.Seo;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Settings;
using VirtoCommerce.SearchModule.Core.Extensions;
using VirtoCommerce.SearchModule.Core.Model;
using static VirtoCommerce.SearchModule.Core.Extensions.IndexDocumentExtensions;

Expand Down Expand Up @@ -148,27 +150,29 @@ protected virtual void IndexCustomProperty(IndexDocument document, Property prop
// Add value to the searchable content field if property type is unknown or if it is present in the provided list
if (contentPropertyTypes == null || contentPropertyTypes.Contains(property.Type))
{
var contentField = property.Multilanguage && !string.IsNullOrWhiteSpace(propValue.LanguageCode)
? $"__content_{propValue.LanguageCode.ToLowerInvariant()}"
: "__content";

switch (propValue.ValueType)
{
case PropertyValueType.LongText:
case PropertyValueType.ShortText:
var stringValue = propValue.Value.ToString();

if (!string.IsNullOrWhiteSpace(stringValue)) // don't index empty values
{
document.Add(new IndexDocumentField(contentField, stringValue.ToLower(), IndexDocumentFieldValueType.String) { IsRetrievable = true, IsSearchable = true, IsCollection = true });
}

document.AddContentString(stringValue,
property.Multilanguage ? propValue.LanguageCode : string.Empty);
break;
}
}
}
}

protected virtual void IndexSeoInformation(IndexDocument document, IList<SeoInfo> seoInfos)
{
foreach (var seoInfo in seoInfos)
{
document.AddContentString(seoInfo.MetaKeywords, seoInfo.LanguageCode);
document.AddContentString(seoInfo.MetaDescription, seoInfo.LanguageCode);
document.AddContentString(seoInfo.PageTitle, seoInfo.LanguageCode);
}
}

protected virtual string[] GetOutlineStrings(IEnumerable<Outline> outlines, bool getNameLatestItem = false)
{
return outlines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ protected virtual IndexDocument CreateDocument(Category category)

IndexCustomProperties(document, category.Properties, new[] { PropertyType.Category });

// Index product descriptions
IndexDescriptions(document, category.Descriptions);

// Index seo information
IndexSeoInformation(document, category.SeoInfos);

if (StoreObjectsInIndex)
{
// Index serialized category
Expand All @@ -140,6 +146,17 @@ protected virtual IndexDocument CreateDocument(Category category)
return document;
}

protected virtual void IndexDescriptions(IndexDocument document, IList<CategoryDescription> descriptions)
{
foreach (var description in descriptions.Where(x => !string.IsNullOrEmpty(x?.Content)))
{
document.AddContentString(description.Content, description.LanguageCode);

var descriptionField = $"description_{description.DescriptionType?.ToLowerInvariant() ?? "null"}_{description.LanguageCode?.ToLowerInvariant() ?? "null"}";
document.Add(new IndexDocumentField(descriptionField, description.Content, IndexDocumentFieldValueType.String) { IsRetrievable = true, IsCollection = true });
}
}

/// <summary>
/// Child categories must inherit "hidden" flag from parent categories
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using VirtoCommerce.SearchModule.Core.Extensions;
using VirtoCommerce.SearchModule.Core.Model;
using VirtoCommerce.SearchModule.Core.Services;
using static VirtoCommerce.SearchModule.Core.Extensions.IndexDocumentExtensions;

namespace VirtoCommerce.CatalogModule.Data.Search.Indexing
{
Expand Down Expand Up @@ -33,7 +34,7 @@ public virtual Task<SearchRequest> BuildRequestAsync(SearchCriteriaBase criteria
request = new SearchRequest
{
SearchKeywords = categorySearchCriteria.Keyword,
SearchFields = new[] { "__content" },
SearchFields = [ContentFieldName],
Filter = filters.And(),
Sorting = GetSorting(categorySearchCriteria),
Skip = criteria.Skip,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ protected virtual IndexDocument CreateDocument(CatalogProduct product)
// Index custom product properties
IndexCustomProperties(document, product.Properties, contentPropertyTypes);

// Index editorial reviews
// Index product descriptions
IndexDescriptions(document, product.Reviews);

IndexSeoInformation(document, product.SeoInfos);

if (StoreObjectsInIndex)
{
// Index serialized product
Expand All @@ -245,8 +247,9 @@ protected virtual void IndexProductVariation(IndexDocument document, CatalogProd
// add the variationId to __variations
document.AddSearchableCollection("__variations", variation.Id);

IndexCustomProperties(document, variation.Properties, new[] { PropertyType.Variation });
IndexCustomProperties(document, variation.Properties, [PropertyType.Variation]);
IndexDescriptions(document, variation.Reviews);
IndexSeoInformation(document, variation.SeoInfos);
}

protected virtual void IndexTypeProperty(IndexDocument document, string value)
Expand All @@ -259,6 +262,8 @@ protected virtual void IndexDescriptions(IndexDocument document, IList<Editorial
{
foreach (var review in reviews.Where(x => !string.IsNullOrEmpty(x?.Content)))
{
document.AddContentString(review.Content, review.LanguageCode);

var descriptionField = $"description_{review.ReviewType?.ToLowerInvariant() ?? "null"}_{review.LanguageCode?.ToLowerInvariant() ?? "null"}";
document.Add(new IndexDocumentField(descriptionField, review.Content, IndexDocumentFieldValueType.String) { IsRetrievable = true, IsCollection = true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using VirtoCommerce.SearchModule.Core.Extensions;
using VirtoCommerce.SearchModule.Core.Model;
using VirtoCommerce.SearchModule.Core.Services;
using static VirtoCommerce.SearchModule.Core.Extensions.IndexDocumentExtensions;

namespace VirtoCommerce.CatalogModule.Data.Search.Indexing
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public virtual async Task<SearchRequest> BuildRequestAsync(SearchCriteriaBase cr
request = new SearchRequest
{
SearchKeywords = productSearchCriteria.Keyword,
SearchFields = new[] { "__content" },
SearchFields = [ContentFieldName],
Filter = GetFilters(allFilters).And(),
Sorting = GetSorting(productSearchCriteria),
Skip = criteria.Skip,
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.802.0" optional="true" />
<dependency id="VirtoCommerce.Core" version="3.808.0" />
<dependency id="VirtoCommerce.Export" version="3.803.0" optional="true" />
<dependency id="VirtoCommerce.Search" version="3.804.0" />
<dependency id="VirtoCommerce.Search" version="3.805.0" />
<dependency id="VirtoCommerce.Store" version="3.809.0" />
</dependencies>

Expand Down

0 comments on commit 8d20c8b

Please sign in to comment.