3

I am using Sitecore 8.1 with Solr 4.10 doing a general site search. I have a repeater on my search results page and I am binding the results to that repeater. For some reason in my QA environment I am getting an error when I try to access searchHit.Document.Paths. It is always coming back as null. This works fine in my local development environment. Could it be a configuration problem? Do I need to re-index? Here is the code from my repeater. It fails on the IF statement because searchHit.Document.Paths is NULL.

    protected void rptResults_OnItemDataBound(object sender, RepeaterItemEventArgs e) {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            var searchHit = (SearchHit<GeneralSearchResultItem>) e.Item.DataItem;
            var hypItem = (HyperLink) e.Item.FindControl("hypItem");
            var spnIcon = (HtmlGenericControl) e.Item.FindControl("spnIcon");
            var litTitle = (Literal) e.Item.FindControl("litTitle");
            var litDescription = (Literal) e.Item.FindControl("litDescription");

            var mediaLibraryRootItem = Sitecore.Context.Database.GetItem("/sitecore/media library");

            if (searchHit.Document.Paths.Contains(mediaLibraryRootItem.ID)) {
                hypItem.NavigateUrl = searchHit.Document.ItemUrl;
                litTitle.Text = searchHit.Document.MediaTitle;
                litDescription.Text = TruncateString(searchHit.Document.MediaDescription, 200);
            }
            else {
                hypItem.NavigateUrl = searchHit.Document.ItemUrl;
                litTitle.Text = searchHit.Document.Title;
                litDescription.Text = TruncateString(searchHit.Document.Description, 200);
            }


            var iconClass = searchHit.Document.IconClass;
            if (iconClass != "") {
                spnIcon.Attributes["class"] = "icon " + iconClass;
            }
        }
    }
  • can you check in your config files if you the stored attribute is true defintion of field _path <field name="_path" type="string" indexed="true" stored="true" multiValued="true" /> – Vlad Iobagiu Oct 17 '16 at 18:26
  • 2
    You need to re-index - yes. – Harsh Baid Oct 17 '16 at 18:32
  • Yes I have the _path field set up as you described – Corey Burnett Oct 17 '16 at 18:34
  • can you check also in schema.xml file if path's stored attribute is true? – Vlad Iobagiu Oct 17 '16 at 18:55
  • @SitecoreClimber - yes that is where I looked. I looked in the schema.xml file. Is is showing there as <field name="_path" type="string" indexed="true" stored="true" multiValued="true" />. This is for the sitecore_web_index core. Is there somewhere else besides that where I should look also? – Corey Burnett Oct 17 '16 at 19:16
2

I rebuilt the index completely and that seems to have fixed the problem. I am no longer getting the NULL error.

0

Since as you say it works on your machine but not on the QA box it does look like environment related(either configurations are not set properly or the value is not being indexed properly. Before you go out comparing configuration files have you tried using an index browser like Luke? with this tool you can easily check what the values are being set on the index for whatever fields you need. If they are properly indexed you know it's not an indexing issue and most likely a misconfiguration between environments. If that's the case I would suggest comparing configs looking for the misconfiguration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.