Copied to clipboard

Flag this post as spam?

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


  • Harry Spyrou 212 posts 604 karma points
    Sep 19, 2016 @ 13:01
    Harry Spyrou
    0

    Help me understand Examine

    Ok, so here's what's going on. I recently started an internship in a company and nobody is helping me with anything. I have been stuck trying to understand Examine for about 5 days now and I still can't write a single line of code. What am I missing?

    What I have been assigned to do is to create a search bar in a project I've been making. The search bar is in various pages. I need it to be able to search throughout the whole website, no filters.

    Here's the problem. The quick start guide won't work because I don't need the search results in the same page but in a different one. I have no idea what the commands are for the surface controllers or where to find them (I'm also pretty sure they're not called commands, but I don't know how to call them). I generally have no clue where to start and my supervisor keeps telling me to create a controller and use mvc for the search bar along with Umbraco. I have no idea what to do and nothing seems to make sense or work. I've read the documentation a thousand times and it won't help me. Any tips on where to start? I need MAJOR help.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 19, 2016 @ 13:33
  • Harry Spyrou 212 posts 604 karma points
    Sep 19, 2016 @ 13:38
    Harry Spyrou
    0

    Hello, Dennis and nice to see you here. Unfortunately they don't. As you can tell from my post, I'm having trouble with the documentation. I don't understand a lot of things. e.g: In the Quick Start Guide, the Indexers that it tells me to add are already there in my project and I don't know if I should add them twice or not. I don't know what they do, I basically don't know anything. I know it sounds ridiculous for someone that uses it regulary but I just can't seem to grasp the basics even before I start using it.

    I also don't know how to actually get a query and return it and so on and so forth through Umbraco and of course Examine. This sucks (for me).

    I've read the documentation a thousand times but I can't seem to figure it out.

    Plus, what about the controller that my supervisor keeps telling me to make? I don't know what to do, literally.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Sep 19, 2016 @ 13:55
    Ismail Mayat
    0

    Harry,

    To get a quick search up use the package ezSearch. Also look through the code to see how it works.

    https://our.umbraco.org/projects/website-utilities/ezsearch/

    Regards

    Ismail

  • Harry Spyrou 212 posts 604 karma points
    Sep 19, 2016 @ 13:57
    Harry Spyrou
    0

    I'd love to but I'm not allowed to. I'm supposed to learn how Examine works and generally how Umbraco works.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Sep 19, 2016 @ 14:58
    Ismail Mayat
    0

    Right, then download the source of it you can learn how to create search

  • Harry Spyrou 212 posts 604 karma points
    Sep 19, 2016 @ 15:00
    Harry Spyrou
    0

    Do you mean the examine source in Github(I think)?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 19, 2016 @ 16:05
    Dennis Aaen
    0

    Hi Harry,

    I think that Ismail mean that you should try to download the source code of the ezSearch package to see how it´s done.

    You can find the GitHub repo here https://github.com/mattbrailsford/ezSearch

    If you want to know how Umbraco CMS works, then I would recommend you to have a look here https://our.umbraco.org/documentation/Getting-Started/

    We have also some videos that shows the basic concepts of Umbraco CMS. you can find them here, https://umbraco.tv/videos/umbraco-v7/

    Some of the videos are free to watch and some needs that you subscribe to the Umbraco TV service.

    Hope this helps,

    /Dennis

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Sep 20, 2016 @ 08:17
    Rasmus Fjord
    0

    Hey Harry and welcome to the best community in da world 😄

    Ill like to help you and im going to this in steps.

    First step is what is examine?

    So think of it like this, when ever a person publishes a page in umbraco, its saved to the database of course and its also saved to the biiiig xml file in app_data/umbraco.config. This also called the content cache.

    Now a signal is send to Examine that there is a page that is created/updated so examine(much like a search robot) "indexes" the page.

    Examine works on indexes where SQL works on tables, when you have tables you search.

    You ask the nice the SQL database do you have any lines where the name starts with "Rasmus", and the database needs to search. This takes time.

    And index works more like a phone book, you know where all names with Rasmus, its under R. So its more of a lookup.

    Now these indexes can be queried, just like you can query an SQL database. When you query an examine database you use something called Lucene Queries(because is build on top of Lucene).


    This was just abit of how examine works or how i like to understand it, its probably not 100% correct but makes it a bit easier to understand.

    You need to tell me here if you are with me so far :)

    Protip #1: Don't think of doing stuff in a controller now, this is just a confusing element. What you can do is just try code out inside an CSHTML file, like a partial view.(use visual studio this helps ALT). Dont build the rocketship on your first day, start with a life raft.


    My first lucene query

     BaseSearchProvider externalSearcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
                ISearchCriteria criteria = externalSearcher.CreateSearchCriteria();
                criteria = criteria.RawQuery("nodeTypeAlias: contentPage AND nodeName:My page");
                SearchResult[] results = externalSearcher.Search(criteria);
      foreach (var searchResult in results)
                    {
                     <p>@searchResult.Fields["nodeName"]</p>   
                    }
    

    So the first line is what to search, we have multiple indexes but the default, externalSearcher, contains our content/media + more. The next few lines we setup or "search criteria", what do we want to find?

    So here i write a RAW query and that is my lucene query: nodeTypeAlias: contentPage AND nodeName:My page

    Get all items of nodeTypeAlias contentPage AND the name must be My page aswell.

    You can test your lucene queries very easily and play around with them, go to the developer section of umbraco and select the examine management.

    enter image description here

    Hope this helps so far:)

  • Harry Spyrou 212 posts 604 karma points
    Sep 20, 2016 @ 12:49
    Harry Spyrou
    0

    Hello Rasmus and thank you, it did help somewhat. However, I'm still supposed to use a controller etc. I have no idea how to do it WITH examine AND a controller. My code so far looks like that :

    SearchResultsPage.cshtml:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Examine;
    @using MyUmbraco.Controllers;
    @using MyUmbraco.Models;
    
    @{ 
        var Searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
    

    var Searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"]; var query = searchCriteria.Field("nodeName","hello").Or().Field("metaTitle","hello").Compile(); var SearchResults = Searcher.Search(query) }

    @* Get the search term from query string *@
    
    
    <head>
    
        @Html.Partial("_HeadIncludes")
    </head>    
    <body>
        @Html.Partial("_Navbar")
    
    
        <div class="container">
            <div class="row">
                <div class="col-md-12 text-center">
                    <ul>
                    @foreach (var result in SearchResults)
                    {
                        <li>
                            <a href="@result.Url">@result.Name </a>
                        </li>
                    }
                        </ul>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
            </div>
            <div class="clear"></div>
        </div>
    
        @Html.Partial("_FooterMenu")
    </body>
    

    SearchSurfaceController.cs:

    using System.Web.Mvc;
    using MyUmbraco.Models;
    using Umbraco.Web.Mvc;
    using Umbraco.Web;
    using System.Collections.Specialized;
    
    namespace MyUmbraco.Controllers
    {
        public class SearchSurfaceController : SurfaceController
        {
    
    
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult HandleTheSearching(SearchBarViewModel model)
            {
                var searchPage = Umbraco.Content(1409); //node
                if (searchPage != null)
                {
                    return new RedirectResult(searchPage.Url, false);
                }
                else
                {
                    return new RedirectResult("/", false);
                }
    
    
            }
        }
    }
    

    SearchBar.cshtml:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<SearchBarViewModel>
    @using MyUmbraco.Controllers
    @using MyUmbraco.Models
    @using Umbraco.Web;
    
    
    
    <div class="row">
        <div class="col-md-12">
    
            @using (Html.BeginUmbracoForm<SearchSurfaceController>("HandleTheSearching"))
            {
                @Html.ValidationSummary(true)
                @Html.AntiForgeryToken()
    
                @*<form action="" method="post" target="_blank" class="input-group input-lg add-on searchbarbackground">*@
                @Html.TextBoxFor(model => model.query, null, new { @class = "input-group input-lg add-on", @method = "post", @target = "_blank" })
    
                <div class="input-group-btn searchbutton">
                    <button class="btn" type="submit" tabindex="2" id="search">
                        <img src="css/images/focal-lense.png" />
                    </button>
                </div>
                @*</form>*@
    
            }
        </div>
    </div>
    
    
    
    
    <script>//the script is the one that tells the controller to send the data to the model. If we don't have that, we can't do anything.
        $(document).ready(function () {
    
            $("#search").click(function (event) {
                event.preventDefault();
                $(this).closest('form').submit();
                return false;
            });
    
        });
    </script>
    

    Do you see the problem? I definitely don't. I have actually no idea what I'm doing (not even doing right or wrong. I have no idea what I'm doing)

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Sep 20, 2016 @ 12:58
    Rasmus Fjord
    0

    Harry, i havnt read your code and im not going to at this point.

    You are trying to learn everything at once, Examine is not something you master in an hour or two and then you master it.

    It might be the end assignment to build it into a surfaceController or something like it. But focus on how to do examine first, THEN do an experiment with a surface controller. At the end combine it. :)

    So stop the focus on the controller and do the examine thing first, get the search to be like you want it, THEN look at the controller part.

    So lets look at your first block the one with examine code.(SearchResultsPage).

    It looks okay to me but the WebsiteSearcher your using is that created ? Why not just use the default ExternalSearcher that is what we use even on big projects.

    And we know it works.

    Do you have a page called "hello" or a page where the field metaTitle is "hello"? Is it in examine, you can check through the examine management dashboard.

    Try in the first place to only look for one thing.

  • Harry Spyrou 212 posts 604 karma points
    Sep 20, 2016 @ 13:04
    Harry Spyrou
    1

    Alright, I figured I'm doing something too complicated for something simple. Thanks, I'm going to try and ditch the controller for a start. I appreciate your help.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies