+1-888-365-2779
Try Now
More in this section

search api

17 posts, 1 answered
  1. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    01 Sep 2010
    Link to this post
    Hello

    I am looking at grabbing the search terms that users enter. Does anyone know how I could grab the search terms people enter in the box? It cant be on the mouse out of the box or whatever because it needs to only store the values ifthose terms were found in the results or not? should i write my own module using the serach API and intercept the bit where the results come back?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    01 Sep 2010
    Link to this post
    Hello LouiseBA,

    You can get the terms after the post of the form is performed. SearchBox and SearchResult are two different controls. SearchBox mainly sends the term in the QueryString of the page and SearchResult reads this QueryString and creates the ResultItems by using SearchManager class. You can get the terms from the QueryString or inside a custom control that inherits SearchResult control and overrides CreateChildControls or another proper method. By default the SearchResult item is created inside CreateChildControls. The SearchManager has a static method Search(string searchQuery, string indexName, int startIndex, int max, string mode, out int totalItems)  that returns IList of items. The last parameter is the total number  of hits for the search query. The actual segment is created by Lucene and we get the best fragments from there  by using Telerik.Lucene.Net.Highlight.GetBestFragment method - highlights chosen terms in a text, extracting the most relevant sections.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    02 Sep 2010
    Link to this post
    ok thanks Ivan, but is there any way of knowing exactly which words were successfully found?

    So the input would be 'cat dog mouse'

    in the results came 10 results, but mouse wasnt in any of them, but 'cat' and 'dog' returned several times each. So my result here would be 'cat', 'dog'  ?

    I'm trying to capture search trends, but dont care about the words that dont exist in the index.
  4. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    02 Sep 2010
    Link to this post
    sorry so what I should have added, is that you said Lucene will return us a fragment with a concentration of words found, highlighted in bold. but I'm not sure how I can capture what i've described from this fragment of text with bold highlights. So is there another method or something i can interrogate?

    thanks
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 Sep 2010
    Link to this post
    Hi LouiseBA,

    GetBestFragment highlights chosen terms in a text. This means that if you type "cat" this string will be highlights in case it is found during crawling of the search engine. Then the ResultItem is created with the proper Title, Url etc.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    02 Sep 2010
    Link to this post
    Hi Ivan,

    I have read about the method and this isn't what I want. this method is at result item level. I need to know, given a set of search inputs, what of those keywords DOES exist in the index, at index level. Maybe this is not possible.

    Basically I'm looking to create a 'search term cloud', like a tag cloud. So build a cloud of terms that have been searched for the most. I can intercept the search function somewhere and write these terms to a table in the database and maintain a hit counter, thats the easy bit. But those terms that appear in the cloud must ONLY be those words that have been searched for by users AND those that exist in the index. It would be so much easier if I could just write a cloud based on all terms searched for EVEN IF they dont exist :(

    Any ideas? if not i'll just have to drop it!
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 Sep 2010
    Link to this post
    Hello LouiseBA,

    We do not save the words that have been searched. Also you cannot know whether a search term is valid or not before you get any result - if someone types a word that does not exist in the segments there is no reason to populate your cloud and you can't know whether there is a matching before the actual Hit of Telerik.Lucene.Net.Search.Hit and Highlighter. There is no easiest way to get the matched words than using the Highlighter options and what the ResultItem returns in the snippet. You can easily get the text between the <strong> tags and build your cloud.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. David
    David  avatar
    78 posts
    Registered:
    29 Dec 2008
    02 Sep 2010
    Link to this post
    Hi LouiseBA,

       Looks like I am able to track search terms from the Sitefinity search box.  When i first set up one of my sites, I place a little class I like to call tracker into my header control.  This piece of code captures and saves to a database the following:

    UserId (if customer is login)
    referer (refering web url)
    remoteaddress (ip address)
    remotehost (ip address)
    EventDatetime
    Useragent (browser info)
    Page (page name the visitor is on) Currently using this to determine popular pages

    With this in place I am able to look into the referer value for items like this:
    IndexCatalogue=Product+Search&SearchQuery=Sand+dollar&WordsMode=AnyWord

    This is requery string from search results page. 

    I am also able to see yahoo, google and bing search terms the same way. 

    Idea for you:
    With a tracking database table you could with some programming build a dynamic search term cloud. 
    You would need to:
    Parse the referer field for you results page 
    Grab text from the querystring SearchQuery
    Load into some type of list; maybe a searchterm object
    Determine which search term has the higest numbers of hits for ranking terms
    set up some rules on what to display in the could

    Hope that gets you started in the right directions.
    David
  9. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    02 Sep 2010
    Link to this post
    firstly, thank you Ivan for your continued help. Your counting strong tags may be a possiblity.

    David, thanks a lot for your reply and suggestion. I dont care how many times each searched word is found, but simply whether its found or not. so if cat and mouse are found at least once each, write that to my search ranking table. if dog is searched for, but not found, dont bother writing to the table. But I still need to know if its found or not. And thats the bit I dont know how to find out programatically. Reading the search terms in the query string still doesnt tell me if its been found or not (and therefore whether to write it to my hit counter, or not)
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    02 Sep 2010
    Link to this post
    Hi LouiseBA,

    Create a custom class that inherits from SearchResults and override CreateChildControls where you will have access to the ResultItem.  Then you can extract the matched values from Snippet property of the ResultItem and  store them in a database table. Then build your search cloud using the snippet data.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    03 Sep 2010
    Link to this post
    Thanks Ivan, I'm having a go now. Ive read lots of posts on this and many people write lots of code to do something quite simple to the search results, like this one http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/custom-search-results.aspx Do I have to do the same or do I just need to override the createchildcontrols method. I'm not sure exactly of the code to grab each result item from within this method..? All I need to do is look at the snippet of the result text of each item and write my own code to write to my tracker table. any pointers greatly appredciated. thanks, Louise.
  12. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    03 Sep 2010
    Link to this post
    sorry one more thing. If i override the SearchResults using a code file in app_code, the search function works the same. Even if I clear the controls as a test. So have I missed a step to get the control to use my overrriden code? I thought by putting it in app_code it will automatically get picked up..thanks
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Sep 2010
    Link to this post
    Hi LouiseBA,

    The default control is used if you have not created SearchResultsControlToolboxItem as suggested in the post.

    Here is the code that you should have inside CrateChildControls to get the Resultem

    protected override void CreateChildControls()
           {
               base.CreateChildControls();
               if (this.layoutCnt.ResultsList != null)
               {
                   var ds = this.layoutCnt.ResultsList.DataSource;
                   if (ds != null)
                   {
                       IList items = (IList)ds;
                       if (items.Count > 0)
                       {
     
                           foreach (ResultItem i in items)
                           {
                               var s = i.Snippet.ToString();
                           }
                       }
                   }
               }

    And it is normal that when you want to do something out of the box to write some code to get the result.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    03 Sep 2010
    Link to this post
    Ok, I now have a control in my toolbox called 'custom search results'. the code looks like this

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Search.WebControls;

    /// <summary>
    /// Summary description for SearchResultCustomControl
    /// </summary>
    ///

    namespace Mycompany.Custom
    {
        [System.ComponentModel.ToolboxItem(typeof(ResultToolboxItemCustom))]
        public class SearchResultCustomControl : CustomSearchResultsControl
        {
            public SearchResultCustomControl()
            {

            }
        }

        public class ResultToolboxItemCustom : Telerik.Web.ToolboxItem
        {
            public ResultToolboxItemCustom()
                : base(typeof(SearchResultCustomControl))
            {
                base.DisplayName = "CustomSearch";
                base.Description = "Custom Search Control";
            }
        }
    }



    and it is registered in my config, so i can drag it into my search results page. but its currently just doing the same behaviour as normal search results, presumably because, in the control properties on the site, there is a field called LayoutTemplatePath in the appearance tab of the control which currently points to {path}/SearchResult.ascx. I have created a copy of this control, with a code behind page, and called it CustomSearch.ascx.

    I *think* this is what I have to do, as far as the front end goes. Now, where exactly do I put my CreateChildControl override code .. in the cs page of this new ascx control? it doesnt quite work because the code behind wants me to inherit the UserControl class (error msg)

    c:\Program Files\telerik\Sitefinity3.7\WebSites\2e2\Sitefinity\ControlTemplates\Search\CustomSearch.ascx.cs(12): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

    when for this override to work it really needs to inherit SearchResult doesnt it?  i know I'm nearly there... thanks.
     
    code behind pasted here..

    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Search.WebControls;
    using Telerik.Search.Engine;
    using Telerik.Lucene.Net;

    public partial class Sitefinity_ControlTemplates_Search_CustomSearch : SearchResult
    {
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            if (this.layoutCnt.ResultsList != null)
            {
                var ds = this.layoutCnt.ResultsList.DataSource;
                if (ds != null)
                {
                    IList items = (IList)ds;
                    if (items.Count > 0)
                    {

                        foreach (ResultItem i in items)
                        {
                            var s = i.Snippet.ToString();
                            i.Snippet = "test test";

                        }
                    }
                }
            }
        }
               
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    03 Sep 2010
    Link to this post
    Hi LouiseBA,

    You need a custom control - class  or a class library. You cannot use a user control and setting the template does not have anything to do with getting the RestultItem. You can skip setting the template, because it will be loaded from the  base class. All you need to do to get the snippet and found words from it is overriding  CreateChildControls as I showed you.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  16. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    05 Sep 2010
    Link to this post
    ..
  17. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    05 Sep 2010
    Link to this post
    finally works. bit of a learning curve on my part. Thanks a lot Ivan.
Register for webinar
17 posts, 1 answered