Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shawn Calvert 31 posts 196 karma points
    Nov 12, 2018 @ 17:33
    Shawn Calvert
    0

    Programmatically republishing a post excludes it from the Examine search results

    We are stumped on this issue and would appreciate any ideas on why this is happening:

    We needed our Examine search results to be weighted by date, so we added a new custom field for adding a boost number, added that field to the search index, and then set up a script to insert numbers based on a set of date ranges (a month old, 3 months old, etc). This approach itself is working, and returning the results in the order we were looking for.

    The issue occurs when we programmatically save and publish the articles after adding or changing the custom boost number. The article will be published in the system -- it will say it is published in the backoffice, and will appear on the site; however, it will now be excluded from the search results. To include it in the search results again, we have to manually click "Save and Publish" in the backoffice.

    Any ideas on why this is happening? We've tried rebuilding the index, with no luck.

    thank you

  • Harry Spyrou 212 posts 604 karma points
    Nov 12, 2018 @ 17:43
    Harry Spyrou
    0

    I think you need to go under the developer section and rebuild the indexes of the Searcher.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Nov 12, 2018 @ 18:13
    Steve Morgan
    0

    Are you doing this via the ContentService?

    Have you got the RaiseEvents flag set to false on the SaveAndPublish event - I would think this needs to be true?

    cs.SaveAndPublish(newNode, 0, *false* );
    

    https://our.umbraco.com/documentation/reference/events/contentservice-events

    Steve

  • James Smith 2 posts 71 karma points
    Nov 13, 2018 @ 01:34
    James Smith
    0

    Steve - thanks for the response. I am working with Shawn (OP) on this issue.

    We are actually using the new SaveAndPublishWithStatus method.

    contentService.SaveAndPublishWithStatus(descendant,0,true);

    I tried the SaveAndPublish method with raiseEvents set to true and we still get the same result - we need to click "Save and Publish" in the back office to have the content included in the Examine searches.

    Fyi - we are not creating new content in the code but editing a custom property of an existing document and saving.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Nov 13, 2018 @ 07:07
    Dave Woestenborghs
    0

    Hi Shawn, James,

    Can we see the code you have ?

    Dave

  • James Smith 2 posts 71 karma points
    Nov 13, 2018 @ 07:19
    James Smith
    0

    Hi Dave, here is the code that is updating the property then saving and publishing the content.

            //Get the Root Content
            var rootContent = contentService.GetRootContent();
            foreach (var content in rootContent)
            {
                switch (content.Name.ToUpper())
                {
                    case "CONTENT":
                        {
                            var descendants = contentService.GetDescendants(content);
                            foreach (var descendant in descendants)
                            {
                                if (descendant.HasProperty("publicationDateSearchWeighting"))
                                {
                                    DateTime pubDate = Convert.ToDateTime(descendant.GetValue("publicationDate"));
                                    Double daysSincePublished = (DateTime.Now - pubDate).TotalDays;
                                    Int32 newBoostValue = 1;
                                    if (daysSincePublished < 7) { newBoostValue = 12; }
                                    else if (daysSincePublished < 14) { newBoostValue = 9; }
                                    else if (daysSincePublished < 28) { newBoostValue = 8; }
                                    else if (daysSincePublished < 91) { newBoostValue = 7; }
    
                    descendant.SetValue("publicationDateSearchWeighting", newBoostValue.ToString());
                    Attempt<Umbraco.Core.Publishing.PublishStatus> attemptResult = contentService.SaveAndPublishWithStatus(descendant,0,true);
                    Console.WriteLine("Attempt result: " + attemptResult.Result + "; Success: " + attemptResult.Success);
                                }
                            }
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
    

    The Console.WriteLine shows attemptResult.Success is "true" and the updated value of "publicationDateSearchWeighting" is shown in the back office but the content is not listed in searches. If we click "Save and Publish" on the content in the back office it immediately shows up in the searches.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 13, 2018 @ 08:19
    Ismail Mayat
    1

    James,

    Any thing in the logs? There may be an error in your document writing event where you set the boost.

    What you are looking to do here is date based decay something we have done before but they way we did it was with nightly reindex job.

    The code for the boost calculation looks like:

    void indexer_DocumentWritingDateBoost(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e) { var field = e.Document.GetField("articleDate"); var docDate = DateTime.Parse(field.StringValue()); var dateDiff = DateTime.Now.Subtract(docDate); var fudge = 1; float hyperbolic = 1f / (1f + (fudge * dateDiff.Days)); float docBoostVal = 1000000f * hyperbolic; e.Document.SetBoost(docBoostVal); }

    Regards

    Ismail

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Nov 13, 2018 @ 11:20
    Steve Morgan
    1

    Hmmm

    Fyi - we are not creating new content in the code but editing a custom property of an existing document and saving.

    I wonder if the content nodes is not being marked as dirty / changed because you're changing a custom property.

    Try adding a dummy, native field (e.g. a text field) and set this to a random string. Does it work then?

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft