Copied to clipboard

Flag this post as spam?

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


  • tofu 9 posts 89 karma points
    Oct 11, 2018 @ 08:33
    tofu
    0

    documentation of Umbraco.Search?

    Hi, thank you for continued support by you guys. This time, I'm creating some sort of blog post (classic...) and with some tags embedded below for each post.

    From the blog post page, there will be a link to "search" page, in which all the posts with the same tag will be displayed in the form of list.

    [Blog Post Side]
        var tags = Model.GetPropertyValue<string[]>("tagName");
        @foreach (var tag in tags)
            {
                <a href=@(String.Format("{0}{1}", "/Search?query=",tag))>  @tag</a>
            }
    

    and then the link generated above will lead to the following search result screen.

    [Search Result Screen]
        @{
        var searchQuery = Request.QueryString["query"];
    
        if (!string.IsNullOrEmpty(searchQuery))    
        {
            <div class="searchresults">
                <p>Posts matching @searchQuery are as follows: <strong></strong></p>
                <ul>
                    @foreach (var result in Umbraco.Search(searchQuery))
                    {
                        <li>
                            <a href="@result.Url">@result.Name</a>
                        </li>
                    }
                </ul>
            </div>
            }
    }
    

    The problem here is that this code seems to count in matches with non-intended fields, such as the creator of the post, which is not ideal. Could you tell us how to apply some sort of properties, or where the general documentation is? I looked around for a while and really didn't find any official document, so I don't know how to do this.

    Thanks,

  • Søren Gregersen 138 posts 679 karma points c-trib
    Oct 11, 2018 @ 09:14
  • Ismail Mayat 4201 posts 8815 karma points MVP admin c-trib
    Oct 11, 2018 @ 10:01
    Ismail Mayat
    100

    Umbraco.Search out of the box will search over all fields. I believe you can pass in your own examine query as there is overload. So you would have to create your own examine query

    see https://our.umbraco.com/Documentation/Reference/Searching/Examine/overview-explanation

    You can then pass that query into Umbraco.Search

    Regards

    Ismail

  • tofu 9 posts 89 karma points
    Oct 12, 2018 @ 07:01
    tofu
    0

    Thanks everyone for letting me know, I configured it according the documentation you informed me of, and successfully put the searching function! (I forgot to delete the indexing after changing it and was wondering why it won't chage...)

    In the course of it, I encountered these two other searching methods, what are they in relation to the Examine class you guys introduced to me? (such as, "this is obsolete/deprecated, or performance-wise not recommended, in terms of security it's better so on and so on)

    I understand Examine is much faster than the other two thanks to Mr.Dennis but is there anything more to it?

    string searchQuery="something";
    
    Umbraco.Search(searchQuery)
    Umbraco.TypedSearch(searchQuery)
    

    Thanks in advance

Please Sign in or register to post replies

Write your reply to:

Draft