Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Apr 22, 2015 @ 11:05
    Jason Espin
    0

    Creating advanced search functionality in Umbraco 7

    Hi all,

    I have a bit of a dilemma with a new project we are due to start in the coming weeks.

    We require an advanced search that allows site visitors on the front end to search through a number of packages on products we have on the site based upon given criteria. The proposed search form can be seen below:

    enter image description here

    Each of these criteria relate to a property field within the document types to be searched and I was wondering what the best approach would be to produce this functionality or whether there is an existing search tool within Umbraco that could be used for these purposes (paid or free).

    I am aware of how to produce a simple Rich-text based search in Umbraco however the documentation is somewhat lacking both on this forum and across the web as to how to perform more useful advanced search methods like the ones proposed above.

    My main area of concern is the Departure Date and Date To fields as this will essential be a range. The dates that a product is available on will be stored in CSV format in an Umbraco field and this field will have to be parsed to not only find the date specified in the departure date but also the date to and any dates in between those specified.

    Any help or guidance on this issue would be greatly appreciated as we have already been told we have to do this project in half the time we asked for and it is kind of getting to the wire right now.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 22, 2015 @ 13:04
    Jeroen Breuer
    0

    Hello,

    I don't have any experience with this kind of search, but you could have a look at Xuntos Faced Search: https://www.xfssearch.com/

    Jeroen

  • Jason Espin 368 posts 1335 karma points
    Apr 22, 2015 @ 13:23
    Jason Espin
    0

    Hi Jeroen,

    Thanks for this but unfortunately the cost of that product is unreasonable in the scope of this project. Furthermore, from the looks of things this requires or works with individual date facets. What we require is for multiple dates to be related to a particular page and for the search field to be displayed on the homepage linking the user to an actual search page.

    Kind regards,

    Jason Espin

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 22, 2015 @ 13:26
    Jeroen Breuer
    0

    Hello,

    Is it a lot of data? Sometimes I build a custom search without examine. For example just a linq query that searches some properies. With linq queries it's also easy to search between dates.

    Jeroen

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 22, 2015 @ 13:33
    Ismail Mayat
    0

    Guys,

    I did something similar ages ago see http://www.world-of-incentives.com/programme-ideas.aspx the search form on submission builds an examine query then does the search.  One thing you will need todo is maybe massage some of the data so it can be searched you do this using gatheringnode data event.  You will need to code this up, i am not aware of any package that will automagically do this for you. With the fields in your form that you have can you let me know what type they are and if they live in umbraco as nodes.

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 22, 2015 @ 13:34
    Ismail Mayat
    0

    Oh that reminds me i did something similar here http://www.thefabricofindustry.com/ and detailed in uhangout video how i did it see http://uhangout.co.uk/videos/ep006-with-ismail-mayat-a-walkthrough-of-a-site-powered-by-examine-searches/

  • Jason Espin 368 posts 1335 karma points
    Apr 22, 2015 @ 15:35
    Jason Espin
    0

    Hi Ismail,

    Thanks for your response. In this case, we will have a page called a tour master. This is essentially all of the common details about a tour that runs on different dates. So for example, common details would be the name, the activities involved and the equipment required.

    Within this tour master, rather than creating an individual page for each departure we will have a property called : departure dates which houses in CSV format (or XML or JSON whichever is best) the dates on which the tour departs.

    So this property would contain something like this:

    02/11/1988, 03/11/1988, 13/12/2013, 14/12/2013, 15/12/2013, 17/12/2013

    Then in our search form on the homepage they would be able to specify that they wish to search for tours that occur between:

    Start Date: 12/12/2013

    End Date: 18/12/2013

    As the example above has dates that feature within this range:

    (13/12/2013, 14/12/2013, 15/12/2013, 17/12/2013)

    It should be returned to the search results page if it complies with the additional search criteria such as category that has been defined in the search form. Each tour can be assigned to multiple categories and is assigned via a property within the tour master that links it to one of the category pages.

    Kind regards,

    Jason Espin

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 22, 2015 @ 16:31
    Ismail Mayat
    0

    Jason,

    Ouch, this has me a little stumped. I would maybe try the following,using gatheringnode data event get the csv list of dates and inject each one in new field so if i have 02/11/1988, 03/11/1988, 13/12/2013, 14/12/2013, 15/12/2013, 17/12/2013 that is six fields injected in like tour_date_1, tour_date_2 etc then do range query grouped or over those dates, although one problem will be knowing how many date fields to range over.  Is there a max no of dates that a tour can occur on? I suspect not? 

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 22, 2015 @ 16:37
    Ismail Mayat
    0

    Jason,

    Not examine but lucene related see http://stackoverflow.com/questions/1655283/lucene-trouble-with-indexing-recurring-events ;

    Regards

    Ismail

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Apr 22, 2015 @ 17:03
    Jason Prothero
    0

    You may just try using Examine for the non-date search fields, the filter the Examine results by date.  Another thing I've done on a project is put the month as a new field in the GatheringNodeData event.  In this case, you could narrow the results to the correct month (and the other non-date fields), then post-process the resutls (which is a much smaller set).

     

    Just a couple of thoughts.

    Thanks,
    Jason 

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 12:31
    Jason Espin
    0

    Hi Ismail & Jason,

    Thanks for your replies. I'm currently in the process of following this tutorial to setup examine and try and get some search results appearing based upon multiple fields in an older project (still Umbraco 7 though):

    http://24days.in/umbraco/2013/getting-started-with-examine/

    I have setup my index as follows:

    <IndexSet SetName="MySearch" IndexPath="~/App_Data/TEMP/ExamineIndexes/MySearch/">
        <IndexAttributeFields>
          <add Name="id" />
          <add Name="nodeName"/>
          <add Name="updateDate" />
          <add Name="nodeTypeAlias" />
        </IndexAttributeFields>
        <IndexUserFields>
          <add Name="days" />
          <add Name="nights" />
          <add Name="cityCode" />
        </IndexUserFields>
        <IncludeNodeTypes>
          <add Name="package" />
        </IncludeNodeTypes>
        <ExcludeNodeTypes>
        </ExcludeNodeTypes>
      </IndexSet>
    

    I have then setup the following index provider:

    <add name="MySearchIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine"
               supportUnpublished="false"
               supportProtected="false"
               interval="10"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
               indexSet="MySearch" />
    

    And search provider:

    <add name="MySearchSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
           analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="MySearch" enableLeadingWildcards="true"/>
    

    This appears to the successfully setup the temporary file under the path specified above however, when I try to rebuild this index from the Developer section is says that nothing has been indexed.

    enter image description here

    I'm also trying to run a simple query from a template page using the code provided in the tutorial above searching for 'BUE' which is a value I know features in one or more of my packages in the citycode property however I am getting an error in Visual Studio that:

    Umbraco.Web.Models.RenderModel does not contain a definition for 'NodeById'

    Any ideas why this isn't working?

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 12:41
    Jason Espin
    0

    Okay so I think I've solved the NodeById bit and have used the following instead:

    var node = Umbraco.Content(item.Fields["id"]);
    

    However, my index is still returning 0 even when I rebuild it. Why is this happening? I have checked the document type alias and it is definitely package so this should be working.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 23, 2015 @ 13:15
    Dave Woestenborghs
    0

    Hi Jason,

    I see you included package as allowed nodetype. Is that the exact alias of your doctype ? 

     

    Can you also post the code that is failing ?

    dave

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 13:23
    Jason Espin
    0

    Hi Dave,

    The document type alias is "package" as I always write my aliases lowercase. I have also checked this in the back office. There are no code errors now (as I fixed these in my template as I mentioned above) however like I say, no pages are being indexed under the new MyIndex in the Umbraco backoffice despite there being a large number of pages with the "package" document type alias.

    Kind regards,

    Jason Espin

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 23, 2015 @ 14:29
    Dave Woestenborghs
    0

    Just a wild guess, but maybe you can hook in to the documentwriting or gathering node data events to see if these get fired when you publish a "package"

    Dave

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 15:01
    Jason Espin
    0

    To be honest I'm starting to think that Examine just doesn't work. I've followed official Umbraco tutorials and yet nothing is being indexed. How would I go about hooking into those as the documentation is somewhat lacking?

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 23, 2015 @ 15:08
    Dave Woestenborghs
    0

    Hey Jason,

    Examine definitly works.We use it in al our sites.

    Do the default indexes work ?

    See below examples to hook in to the events.

    public class Registration : ApplicationEventHandler
        {
    
    
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
    
                // register examine events
                var helper = new UmbracoHelper(UmbracoContext.Current);
                var indexer = (UmbracoContentIndexer)ExamineManager.Instance.IndexProviderCollection["MySearchIndexer"];
    indexer.GatheringNodeData += (sender, e) => GatheringContentData(sender, e, helper); indexer.DocumentWriting += DocumentWriting; base.ApplicationStarted(umbracoApplication, applicationContext); } public void DocumentWriting(object sender, DocumentWritingEventArgs e) { } public void GatheringContentData(object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper) { } }

    Dave

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 15:08
    Jason Espin
    0

    Okay looking at my code I think I've found an issue in my indexer definition

    <add name="MySearchIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine"
               supportUnpublished="false"
               supportProtected="false"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
               indexSet="MySearch" />
    

    should be

    <add name="MySearchIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
               supportUnpublished="false"
               supportProtected="false"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
               indexSet="MySearch" />
    

    it appears I may have been using a member indexer rather than a content one.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 23, 2015 @ 15:12
    Dave Woestenborghs
    0

    I'm sure that is the cause.

    Dave

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 16:59
    Jason Espin
    0

    That was the initial cause of the issues we were facing but in general Examine just doesn't seem to be very reliable.

    We have setup a new document type with an alias of "tour" which has the following property and values:

    tripType - "Private Tours"

    However when we run the following query, nothing is returned:

        string difficulty = "Easy";
        string type = "Private Tours";
        DateTime dateFrom = new DateTime(20151115);
        DateTime dateTo = new DateTime(20151117);
        string duration = "2-5 days";
    
        var searcher = ExamineManager.Instance.SearchProviderCollection["ToursSearcher"];
        var searchCriteria = searcher.CreateSearchCriteria();
        var query = searchCriteria.Field("tripType""Private Tours").Compile();
        var searchResults = searcher.Search(query); 
    }
    
    <ul>
        @foreach (var item in searchResults)
        {
            IPublishedContent node = Umbraco.Content(item.Fields["id"]);
            <li>
                <a href="@node.Url">
                    @node.Name
                </a>
            </li>
        }
    </ul>

    What should be returned is the two tour pages that we have created with this type.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 23, 2015 @ 17:05
    Ismail Mayat
    0

    Jason,

    can you open you index using luke and see if you have any docs, https://code.google.com/p/luke/downloads/list v350, it may be that you have no docs in your index. 

    Regards

    Ismail

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 17:16
    Jason Espin
    0

    The Umbraco back office specifies that we have two documents in our Index

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 17:16
    Jason Espin
    0

    The Umbraco back office specifies that we have two documents in our Index

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 17:26
    Jason Espin
    0

    I have also tried opening the index files in Luke and confirm that the pages and the data we wish to search for are there.

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Apr 23, 2015 @ 17:34
    Jason Prothero
    0

    Try doing a manual search using the search tools at the bottom of the Examine Manager tab.  It may help to print our the compiled Lucene query to the page to get the exact search.

     

     

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 17:39
    Jason Espin
    0

    I have tried doing just a manual text search in the search tools and nothing is returned. It's odd because I have had a look in Luke and the data is indexed in there as expected but when I try and run a Lucene query in Luke or in Umbraco nothing is returned.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 23, 2015 @ 17:53
    Dave Woestenborghs
    0

    So what query are you executing ? Maybe there is a error in the query ?

    Dave

  • Jason Espin 368 posts 1335 karma points
    Apr 23, 2015 @ 17:54
    Jason Espin
    0

    We had the wrong analyzer included. Should have been this (apologies its been a long day):

    analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 23, 2015 @ 17:57
    Dave Woestenborghs
    0

    Glad you sorted it out.

    Dave

  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    Apr 23, 2015 @ 18:18
    Jason Prothero
    0

    Good to hear!

Please Sign in or register to post replies

Write your reply to:

Draft