Copied to clipboard

Flag this post as spam?

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


  • sabueXo 12 posts 32 karma points
    Jun 19, 2012 @ 14:26
    sabueXo
    0

    Search JSON. I can't do it work...

    Hi,

    I am trying to implement this functionality on my webpage. It is the first time that I create a webpage using Umbraco and I am still learning...

    Can anyone tell me what I am doing wrong?

    When the search is launched, the result always is empty... nothing returns...

    Here is mi code:

    ExamineIndex.config

    <!-- Index set for search box -->
        <IndexSet SetName="SearchBoxIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/SearchBox/">
            <IndexAttributeFields>
                <add Name="id" />
                <add Name="nodeName" />
                <add Name="updateDate" />
                <add Name="writerName" />
                <add Name="path" />
                <add Name="nodeTypeAlias" />
                <add Name="parentID" />
            </IndexAttributeFields>
            <IndexUserFields>
                <add Name="newsText" />
            </IndexUserFields>       
            <IncludeNodeTypes>
                <add Name="News" />
            </IncludeNodeTypes>
            <ExcludeNodeTypes />
        </IndexSet>

     

     ExamineSettings.config

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

    <add name="SearchBoxSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="SearchBoxIndexSet" />

    SearchJSON.cshtml

    @using Examine
    @using Examine.SearchCriteria
    @using System.Web.Script.Serialization

    @{
        //Get the domain (http://localhost:6436)
        var siteURL = "http://" + Request.Url.Authority;
       
        //Get the values posted from the form
        var searchTerm = Request["term"];

        //Check if searchTerm is null from the posted form data...
        if (String.IsNullOrEmpty(searchTerm))
        {
            //Stop all other code running in this Macro
            return;
        }

        var searcher = ExamineManager.Instance.SearchProviderCollection["SearchBoxSearcher"];
        var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
        var query = searchCriteria.GroupedOr(new string[] { "newsText" }, searchTerm).Compile();
        var searchResults = searcher.Search(query);
       
        /*
        EXAMPLE JSON
        [{ "id": "http://localhost/about.aspx", "label": "About", "value": "About" }]
        */

        List<dynamic> searchResultKeyVals = new List<dynamic>();
       
        //Convert the search results as JSON
        foreach(var result in searchResults)
        {
            searchResultKeyVals.Add(new {
                id = siteURL + umbraco.library.NiceUrl(result.Id),
                label = result.Fields["newsText"],
                value = result.Fields["newsText"]
            });
        }
       
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        var JSONResults = serializer.Serialize(searchResultKeyVals);   
    }

    @* Ouput the JSON *@
    @Html.Raw(JSONResults)

    Thanks!

  • sabueXo 12 posts 32 karma points
    Jun 19, 2012 @ 18:12
    sabueXo
    0

    I have installed Examine Dashboard and I get this:

    Queue

    1 file in queue -> Last update 6/19/2012 9:09:00 AM

     Number of documents

    0

    Log

    19/06/2012 09:07:36 [UmbracoExamine] Adding examine event handlers for index providers: 3
    19/06/2012 09:07:36 [UmbracoExamine] (InternalIndexer) Index is being optimized
    19/06/2012 09:07:36 [UmbracoExamine] (SearchBoxIndexer) Index is being optimized
    19/06/2012 09:07:36 [UmbracoExamine] (InternalMemberIndexer) Index is being optimized
    19/06/2012 09:05:18 [UmbracoExamine] Adding examine event handlers for index providers: 3
    19/06/2012 09:05:18 [UmbracoExamine] (SearchBoxIndexer) Index is being optimized
    19/06/2012 09:05:18 [UmbracoExamine] (InternalIndexer) Index is being optimized
    19/06/2012 09:05:18 [UmbracoExamine] (InternalMemberIndexer) Index is being optimized

    ....

    What I am doing wrong????¿?

  • sabueXo 12 posts 32 karma points
    Jun 20, 2012 @ 17:57
    sabueXo
    0

    I have instaled "Examine Dashboard" to know what is happen and these are the results:

    - InternalIndexer

    This one comes whit Umbraco and works fine.

    - InternalMemberIndexer

    This one comes whit Umbraco and generates a queue file but this is all.... nothing is indexed.

    - SearchBoxIndexer

    I have created this one and generates a queue file but this is all.... nothing is indexed.

    Any idea????

Please Sign in or register to post replies

Write your reply to:

Draft