Copied to clipboard

Flag this post as spam?

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


  • Jin Botol 134 posts 287 karma points
    Aug 22, 2018 @ 07:39
    Jin Botol
    0

    ExamineIndexes not working properly

    Hi all,

    I got a problem regarding returning TotalProducts.

    This is my code :

    var machineName = Environment.MachineName;
    string indexPath = string.Format($"~/App_Data/TEMP/ExamineIndexes/{machineName}/External/Index");
    
    var indexDirectory = FSDirectory.Open(new DirectoryInfo(HttpContext.Current.Server.MapPath(indexPath)));
    
    var searcher = new IndexSearcher(indexDirectory, true);
    
    var masterQuery = new BooleanQuery();
    
    var bed = string.IsNullOrEmpty(model.Bed) ? 0 : Convert.ToInt32(model.Bed);
    var bedQuery = ConstructIntRangeQuery("intBeds", 0, bed, bed);
    masterQuery.Add(bedQuery, BooleanClause.Occur.MUST);
    
    TopDocs resp = searcher.Search(masterQuery, null, searcher.MaxDoc());
    Debug.WriteLine(resp.TotalHits, "Total Products");
    

    resp.TotalHits is always returning 79 products, even if I have 71 total products.

    This code is working before in my previous version in Umbraco which is 7.5.6, but when I upgrade it into 7.11.1 is not properly working anymore. It's always returning 79 results, even if I add/delete products.

    Any ideas?

    Thanks,

    Jin

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 22, 2018 @ 08:01
    Dave Woestenborghs
    0

    Hi Jin,

    I see you are using your own code. Maybe you can try using the Examine API to do this

    https://our.umbraco.com/Documentation/Reference/Searching/Examine/examine-manager

    Have you tried rebuilding your index ?

    Dave

  • Jin Botol 134 posts 287 karma points
    Aug 22, 2018 @ 08:08
    Jin Botol
    0

    Hi Dave,

    Yes, it's own code, but I am not the one who code it because I am the second developer who handle this site.

    I posted about Examine HERE.

    Yes, I already rebuilding my indexes in Developer sections, both internal & external, but still not working.

    Thanks,

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 22, 2018 @ 09:48
    Jin Botol
    0

    I've already get it.

    I get the nodeId, now how can I get the nodeName and the other fields like title, price, body, etc...

    CODE :

    var bed = string.IsNullOrEmpty(model.Bed) ? "0" : model.Bed;
    var searchQuery = searchCriteria.NodeTypeAlias("Product").And().Field("bedrooms", bed);
    var searchResults = searcher.Search(searchQuery.Compile());
    
    foreach (var searchResult in searchResults)
    {
        Debug.WriteLine(searchResult.Id, "Search ID");
    }
    

    Cheers,

    Jin

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 22, 2018 @ 09:50
    Dave Woestenborghs
    100

    Hi Jin,

    To retrieve other fields from the result you can do this ;

    searchResult.Fields["title"] 
    

    Dave

  • Jin Botol 134 posts 287 karma points
    Aug 22, 2018 @ 09:52
    Jin Botol
    0

    Hi Dave,

    Success!!!!

    Thanks for your help. Problem solved.

    You save my day!

    Thanks,

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 22, 2018 @ 10:00
    Jin Botol
    0

    Hi Dave,

    Another problem regarding when user not selected a bedrooms.

    var bed = string.IsNullOrEmpty(model.Bed) ? "0" : model.Bed;
    var searchQuery = searchCriteria.NodeTypeAlias("Product").And().Field("bedrooms", bed);
    

    This code will return 0, and there is no display.

    How can I set the value of model.Bed if users didn't select a bedrooms?

    Thanks,

    Jin

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 22, 2018 @ 10:04
    Dave Woestenborghs
    0

    Maybe don't include the bed "filter" in your search criteria when it's not set by the user.

    Dave

  • Jin Botol 134 posts 287 karma points
    Aug 22, 2018 @ 10:05
    Jin Botol
    0

    Hi Dave,

    You mean in my Angular?

    Thanks,

    Jin

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 22, 2018 @ 10:11
    Dave Woestenborghs
    1

    Nope in your c# code. Something like this

    var bed = string.IsNullOrEmpty(model.Bed) ? "0" : model.Bed;
    var searchCriteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria(IndexTypes.Content);
    
                    var searchQuery = search.NodeTypeAlias("Product");
    
                    if (bed != "0")
                    {
                        searchQuery .And().Field("bed", Models.bed)
                    }
    

    Dave

  • Jin Botol 134 posts 287 karma points
    Aug 23, 2018 @ 03:10
    Jin Botol
    0

    Hi Dave,

    Oh,

    Thanks to your code, what I did is :

    var bed = string.IsNullOrEmpty(model.Bed) ? "" : model.Bed;
    

    It works well.

    Thanks again, for the help!

    Cheers,

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 23, 2018 @ 03:41
    Jin Botol
    0

    Hi Dave,

    If users selects 5+ Bedrooms.

    How can I query and display all products with more than 5 Bedrooms?

    Thanks,

    Jin

  • Jin Botol 134 posts 287 karma points
    Aug 23, 2018 @ 06:52
    Jin Botol
    0

    Hi,

    I've tried this code, but it's not working...

    var bed = string.IsNullOrEmpty(model.Bed) ? "" : model.Bed;
    if (bed == "5")
    {
        searchQuery.And().Range("bedrooms", 0, Convert.ToInt32(bed), true, true);
        // This code is no display.
    }
    else
    {
        searchQuery.And().Field("bedrooms", bed);
    }
    

    Any ideas, for this.

    Thanks,

    Jin

Please Sign in or register to post replies

Write your reply to:

Draft