Tag Based Recommender is a simple tag-based recommendation library for Sitecore.
Warning: This software is in early stage of development.
This software is tested on the following environment.
- Sitecore: XM/XP 9.3
- SearchProvider: Solr
Not released yet. Clone this repository and build it locally.
- Add a
Tags
field to a page template. - (Optional) Set the template's ID to
TagBasedRecommender.SearchTemplate
settings.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="TagBasedRecommender.SearchTemplate">
<patch:attribute name="value">{The template's ID here}</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
- Now you can get recommendations with
IRecommendationService.GetRecommendations
method.
using TagBasedRecommender.Services;
public class RecommendExample
{
public RecommendExample(IRecommendationService service)
{
var recommendations = service.GetRecommendations(count: 10);
}
}
Note: Each setting name has TagBasedRecommender
prefix (e.g. TagBasedRecommender.SearchField
).
Name | Type | Description | Default |
---|---|---|---|
SearchField |
string |
An index field name for search by tags. | _content |
SearchTemplates |
ID[] |
Template IDs to use filtering recommendation. | empty (All templates) |
StoredItemCount |
int |
A length of items stored in the cookie. | 20 |
BoostMultiplicand |
float |
A value to be added to boosting when a tag is matched. | 1 |
FilterStoredItems |
bool |
When set true, items stored in the cookie are filtered from recommendations. | false |
FilterContextItem |
bool |
When set true, a context item is filtered from recommendations. | true |
Cookie.Name |
string |
A cookie's name (required). | tagbasedrec_items |
Cookie.Lifespan |
int |
A cookie's lifespan to set to Expire attribute (in days). |
30 |
Cookie.Domain |
string |
A cookie's Domain attribute. |
empty |
Cookie.Path |
string |
A cookies's Path attribute. |
/ |
Cookie.Secure |
bool |
A cookie's Secure Attribute. |
true |
Cookie.HttpOnly |
bool |
A cookie's HttpOnly attribute. |
true |
This library uses item's Tags
field to get recommendation tags (splited at whitespace). This behaviour can be customized by replacing DefaultItemTagsResolver
.
using TagBasedRecommender.Services;
public class CategoryTagsResolver : IItemTagsResolver
{
public List<string> GetTags(Item item)
{
// Default
// return item["Tags"].Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries).ToList();
// Use categories's name instead.
var tags = (MultilistField)item.Fields["Categories"];
return tags.GetItems().Select(tag => tag["Name"]).ToList();
}
}
And replace the default resolver by applying the following configuration (This is just an example).
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<services>
<register serviceType="TagBasedRecommender.Services.IItemTagsResolver, TagBasedRecommender">
<patch:attribute name="implementationType">Namespace.To.CategoryTagsResolver, AssemblyName</patch:attribute>
</register>
</services>
</sitecore>
</configuration>
WIP
- Takumi Yamada (xirtardauq@gmail.com)
Tag Based Recommender is licensed under the MIT license. See LICENSE.txt.