Copied to clipboard

Flag this post as spam?

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


  • Arno 10 posts 111 karma points
    Apr 05, 2019 @ 12:36
    Arno
    0

    Umbraco search function

    Hi there,

    I'm trying to implement a basic search functionality on Umbraco 8. So I created a search page, and here is my template:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Search>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
    }
    
        <div class="container">
                    @{
                        var searchQuery = Request.QueryString["query"];
    
                        if (!string.IsNullOrEmpty(searchQuery))    
                        {
                            <div class="searchresults">
                                <p>Your search results for <strong>@searchQuery</strong></p>
                                <ul>
                                    @foreach (var result in Umbraco.Search(searchQuery))
                                    {
                                        <li>
                                            <a href="@result.Url">@result.Name</a>
                                        </li>
                                    }
                                </ul>
                            </div>
                         }else{
                            <h1>No results</h1>
                         }
                    }
                </div>
    

    But I got a compilation error when trying to use Umbraco.Search():

    enter image description here

    Any ideas?

    Thanks

  • Rhys Hamilton 140 posts 942 karma points
    Apr 05, 2019 @ 14:45
    Rhys Hamilton
    102

    Instead of Umbraco.Search, try using Umbraco.ContentQuery.Search.

    If you're looking for a good reference point, Paul Seal put together a nice little Umbraco Starter Kit for V8, which has a working search example here.

  • Arno 10 posts 111 karma points
    Apr 05, 2019 @ 14:52
    Arno
    1

    Thanks a lot Rhys you saved my day!

    Why isn't this documented though :(

  • Rhys Hamilton 140 posts 942 karma points
    Apr 05, 2019 @ 15:01
    Rhys Hamilton
    1

    I'm glad that resolved things for you (remember to mark the solution so others can find it if they experience a similar issue).

    At the moment the documentation is being updated, but you're right that things aren't quite up to date just yet.

    On the flip side, that just means you (and the rest of us using V8) get to lead the charge on this! If you find any outdated documentation (or can't find any documentation at all), you can always raise this as an issue here or contribute yourself! :)

    There's more on this here.

Please Sign in or register to post replies

Write your reply to:

Draft