I have a large number of fields across different document types that should be indexed in my custom indexer but Examine is not indexing them correctly.
It is very strange as the Umbraco back end suggests the fields are being indexed (as shown above - visitedCities, visitedCountries) however when I run the following code and look for the key "visitedCities" I get a key not found exception.
public static class ExamineEvents
{
public static void GatheringContentData(object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper)
{
IPublishedContent content = null;
IPublishedContent homepage = null;
try
{
content = helper.TypedContent(e.NodeId);
homepage = content.AncestorOrSelf("homepage");
e.Fields.Add("siteNode", homepage.Id.ToString());
}
catch (System.NullReferenceException ex)
{
if (e.Fields["level"] != "1")
{
IContentService cs = ApplicationContext.Current.Services.ContentService;
IContent[] unpublishedPageAncestors = cs.GetAncestors(e.NodeId).ToArray();
if (unpublishedPageAncestors.Where(x => x.ContentType.Alias.ToLower() == "homepage").Count() == 1)
{
int id = unpublishedPageAncestors.First().Id;
e.Fields.Add("siteNode", id.ToString());
}
}
else
{
e.Fields.Add("siteNode", e.Fields["id"]);
}
}
catch (Exception ex)
{
// Do Nothing
}
if (e.Fields["nodeTypeAlias"] == "package")
{
try
{
if (!e.Fields["visitedCities"].IsNullOrWhiteSpace())
{
List<string> countries = new List<string>();
List<string> cities = e.Fields["visitedCities"].Split(',').ToList();
foreach (string city in cities)
{
IEnumerable<IPublishedContent> nodes = homepage.Descendants("city").Where(x => x.GetPropertyValue<string>("cityCode") == city);
if (nodes.Count() > 0)
{
try
{
IPublishedContent page = nodes.First();
IPublishedContent country = page.Ancestor("country");
countries.Add(country.GetPropertyValue<string>("countryCode"));
}
catch (Exception)
{
}
}
}
string csv = String.Join(",", countries.Distinct().ToArray());
e.Fields["visitedCountries"] = csv;
}
}
catch (Exception ex)
{
}
}
}
}
Why is examine not indexing these fields correctly and how can I force it to do so?
By default, Umbraco seems to index all custom fields but some it just randomly ignores. I have tried explicitly adding the fields that are missing to the ExamineIndex.config file using the IndexUserFields field however this then causes all other custom fields to be ignored and it still fails to index the fields I have specified.
I have already done that and unfortunately it never hits because it is not detecting that field. I have checked the index with Luke and the fields are being indexed but Umbraco doesn't seem to be detecting them properly in Examine.
Also you should always do check for the field because if you have content that does not have the value then the field will not present in the dictionary.
Was a fix ever found for this? I get the same issue on Umbraco 7.5.11: indexed field shows in Luke from a custom indexer, but when searching, it is not found.
I just had this issue and (thanks to Ismail's comment) added a field check for the field I was looking for....
if (result.Fields.Where(f => f.Key == "myField").Any()){
// do stuff here
}
It only take a single node without that field to kill the loop so even if you can see results in Luke or in the Examine Management panel unless they ALL do you're in trouble.
Examine fails to index custom fields correctly
Hi all,
I have a large number of fields across different document types that should be indexed in my custom indexer but Examine is not indexing them correctly.
It is very strange as the Umbraco back end suggests the fields are being indexed (as shown above - visitedCities, visitedCountries) however when I run the following code and look for the key "visitedCities" I get a key not found exception.
Why is examine not indexing these fields correctly and how can I force it to do so?
By default, Umbraco seems to index all custom fields but some it just randomly ignores. I have tried explicitly adding the fields that are missing to the ExamineIndex.config file using the IndexUserFields field however this then causes all other custom fields to be ignored and it still fails to index the fields I have specified.
Jason,
Add break point to your code then publish just one item that has the fields and see if it hits your break point then step through.
Regards
Ismail
Hi Ismail,
I have already done that and unfortunately it never hits because it is not detecting that field. I have checked the index with Luke and the fields are being indexed but Umbraco doesn't seem to be detecting them properly in Examine.
Cheers,
Jason
What kind of data should be in there is it country / city codes?
Also you should always do check for the field because if you have content that does not have the value then the field will not present in the dictionary.
Hi Ismail,
It is a CSV string of values that list country, city nodes. I can see the field is there in the index but Umbraco fails to even look for it.
Cheers,
Jason
Was a fix ever found for this? I get the same issue on Umbraco 7.5.11: indexed field shows in Luke from a custom indexer, but when searching, it is not found.
I just had this issue and (thanks to Ismail's comment) added a field check for the field I was looking for....
It only take a single node without that field to kill the loop so even if you can see results in Luke or in the Examine Management panel unless they ALL do you're in trouble.
is working on a reply...