Just return 0 is enough. You can try to search for a product after rebuild the index. If it is not found then it was not indexed, right?
And if the product shall be indexed I return base.IndexCatalogEntryDto(indexer, entryRow, defaultCurrency, languages); ? That row always seems to return 1.
yes, just return that.
The result is actually the number of languages you have in your catalog
Okay. So, when 1 is returned from that overriden method, that particular entry is indexed?
Yes. But I'm not sure why you should care about it.
public class CustomCatalogIndexer : CatalogIndexer
{
protected override int IndexCatalogEntryDto (...)
{
if (ShouldNotIndex(entryRow))
{
return 0;
}
return base.IndexCatalogEntryDto(...)
}
}
Perhaps there have been some misscommunication. After I added this overriden method, no products are indexed, which makes me wonder.
this is my code
protected override int IndexCatalogEntryDto(IndexBuilder indexer, CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency, string[] languages) { var entryLink = _referenceConverter.GetEntryContentLink(entryRow.CatalogEntryId); var bySource = _relationRepository.Service.GetRelationsBySource<NodeRelation>(entryLink); var product = _contentLoader.Service.Get<ProductContent>(entryLink); var node = product.GetNodeRelations().FirstOrDefault(); if (node != null) { var currentNode = _contentLoader.Service.Get<NodeContent>(node.Target); if (_indexingService.ShallBeIndexed(currentNode)) { //if (product.DisplayName.Contains("daniels")) //{ return base.IndexCatalogEntryDto(indexer, entryRow, defaultCurrency, languages); //} } } return 0; }
Some comments:
var currentNode = _contentLoader.Service.Get<NodeContent>(node.Target);
line ?
_indexingService.ShallBeIndexed(currentNode)
ShallBeIndexed check if the node has a parent with name "private", if so the product will be indexed, in other case not. My product is under the private-node, but does not show up in my product-variable in my method. I start to think that this row is not fetching the right stuff that I intend:
var entryLink = _referenceConverter.GetEntryContentLink(entryRow.CatalogEntryId);
I am only indexing products in this case.
var entryLink = _referenceConverter.GetEntryContentLink(entryRow.CatalogEntryId);
this should work.
can you post the code of your ShallBeIndexed here?
public bool ShallBeIndexed(IContent currentNode) { if (currentNode.ParentLink != null) { var node = _contentLoader.Service.Get<CatalogContentBase>(currentNode.ParentLink); if (node.Name.Equals("Privat")) { return true; } else { return ShallBeIndexed(node as IContent); } } else return false; }
I misspelled Privat earlier, the name of my catalog node is Privat, and not Private.
It seems that you are skipping the currentNode. So if your structure is like this
Catalog => Node => Privat Node => product
then you are checking Node and Catalog, but not Privat Node.
As a side comment ShallBeIndexed should take CatalogContentBase and you don't have to cast it back to IContent.
My structure looks more like Catalog => Private Node => Category => product. So that shouldn't be an issue here.
Then let's get back to the original question: can you debug it and does it hit the code inside
ShallBeIndexed
The overridden method IndexCatalogEntryDto has the effect that nothing gets indexed. If I comment out that method, products gets indexed as normal. Strange this is.
The problem I now have at hand is getting a node's parent node in accorance with episerver commerce catalog tree. How can this be achived?
node.ParentLink should point you to the direct parent of a node. However if you are looking at linked nodes, you would need to use GetRelationsBySource(node.ContentLink)
Well, I can get the products parent node, but not the parent node's parent node. The only clue I got is that the parent/child relationship may not follow the commerce tree.
Sorry, I now realized my misstake. The parent actually was retreived as it should.
It turned out that our index was malfunctioning for other reasons. The solution provided by Quan in this thread worked as expected on our test and production servers.
I would like to NOT index every product in my catalogue. I am overriding the method IndexCatalogEntryDto by inherritence from CatalogIndexBuilder. What do I return if the product entry should not be indexed?