Copied to clipboard

Flag this post as spam?

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


  • Saif Obeidat 79 posts 294 karma points
    Aug 28, 2019 @ 11:04
    Saif Obeidat
    1

    Or() in Examine doesn't work with me | Umbraco 8

    Hello all,

    I am using Examine to return some nodes, all is fine except when I add Or() to the query.. it returns no results.

    Am I using it wrongly ?

    results = searcher.CreateQuery()
                                .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And()
                                .Field("__IndexType", "content").And()
                                .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And()
                                .Field("parentID", selectedYear != 0 ? selectedYear : "").And()
                                .Field("nodeName", selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).Or()
                                .Field("title", selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).And()
                                .Field("__NodeTypeAlias", "newsLetter").Execute();
    

    Thanks

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Aug 28, 2019 @ 16:15
    Shaishav Karnani from digitallymedia.com
    0

    Hi Saif,

    Please can you try this query instead and see if it works for you. I have tried with GroupedOr

                    var fields = new List<string> { "nodeName", "title" };
                    results = searcher.CreateQuery()
                                                .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And()
                                                .Field("__IndexType", "content").And()
                                                .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And()
                                                .Field("parentID", selectedYear != 0 ? selectedYear : "").And()
                                                .GroupedOr(fields, selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).And()
                                                .Field("__NodeTypeAlias", "newsLetter").Execute();
    
  • Saif Obeidat 79 posts 294 karma points
    Aug 31, 2019 @ 14:13
    Saif Obeidat
    0

    It worked! ..

    but with this way, but it didn't return all nodes when the search term was null or empty string..

    how could I make the query return results when the search term is empty string?

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Aug 31, 2019 @ 14:18
    Shaishav Karnani from digitallymedia.com
    0

    Hi Saif,

    We can have if check to fix this issue.

                    var fields = new List<string> { "nodeName", "title" };
    if (!string.IsNullOrEmpty(searchTerm)) {
                    results = searcher.CreateQuery()
                                                .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And()
                                                .Field("__IndexType", "content").And()
                                                .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And()
                                                .Field("parentID", selectedYear != 0 ? selectedYear : "").And()
                                                .GroupedOr(fields, selectedTerm != "" ? searchTerm.ToString() : searchTerm.ToString()).And()
                                                .Field("__NodeTypeAlias", "newsLetter").Execute();
    }
    else {
                    results = searcher.CreateQuery()
                                                .Field("path", Model.Path.ToString().MultipleCharacterWildcard()).And()
                                                .Field("__IndexType", "content").And()
                                                .Field("articleCountry", (countryUDI != null ? countryUDI.ToString() : "")).And()
                                                .Field("parentID", selectedYear != 0 ? selectedYear : "").And()
                                                .Field("__NodeTypeAlias", "newsLetter").Execute();
    }
    
  • Saif Obeidat 79 posts 294 karma points
    Aug 31, 2019 @ 14:29
    Saif Obeidat
    0

    Hi Shaishav,

    We have already tried that, but we are searching for a better way, isn't there? because we duplicate some code.

Please Sign in or register to post replies

Write your reply to:

Draft