I'm trying to implement a tagging functionality that allows the content editor to add tags for a specific component and the c# to search for items containing a given set of tags
Let's say our Sitecore Lucene index looks like this
x = ["csharp", "dotNet", "java", "vbnet", "c"]
y = ["csharp", "computers", "dotNet"]
z = ["java"]
I want to perform a search query like this
["csharp", "dotNet"]
and have it return x and y, but y will be scored/ranked higher than x because it has more matches than any other items in the index...
I'm familiar with Elastic Search(which is built on Lucene) and I know the way to do this is
{
"terms" : {
"tags" : [ "csharp", "dotNet" ]
}
}
but unsure as the same can be achieved using the ContentSearchAPI in Sitecore Lucene.
My current code is
var tags = GetTagsFromSomewhere();
using (var context = SearchIndexResolver.GetIndex(ContextItem).CreateSearchContext())
{
var queryable = context.GetQueryable<CustomType>();
foreach (var tag in tags)
{
queryable = queryable
.Where(i => i.Tags.Contains(tag));
var results = queryable.GetResults();
}
}
Thanks