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

Forums / Developing with Sitefinity / How to perform "LIKE" Search

How to perform "LIKE" Search

4 posts, 2 answered
  1. Dave Ranck
    Dave Ranck avatar
    14 posts
    Registered:
    30 Oct 2003
    29 Jan 2010
    Link to this post
    Hello,

    Currently our Sitefinity search is performing an "=" search, and only returning values that match the exact search term. We need to configure the search to perform a "LIKE" search - can anyone tell me how this is done.

    Thanks!
    MB
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Feb 2010
    Link to this post
    Hi Mike Brady,

    You can set the EscapeSpeciaChars property of the SearchResult control in order to enable wildcard and fuzzy searches, refer to attached image. For more information on the Search functionality in Sitefinity you can take a look at the following webinar: Working with Sitefinity Search.

    You can also put some javascript to automatically insert * symbols if you want to return matches not only exact word matches. To do so modify the~/Sitefinity/ControlTemplates/Search/Searchbox.ascx:

    Copy Code
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <script type="text/javascript">
        function Click() {
            var queryText = document.getElementById('<%=queryText.ClientID %>');
            queryText.value = '*' + queryText.value + '*';
            debugger;
        }
    </script>
     
    <sfWeb:CssFileLink ID="CssFileLink1"FileName="~/Sitefinity/ControlTemplates/Search/searchCommonLayout.css"Media="screen" runat="server" />
     
    <fieldset class="sf_searchBox">
        <asp:Label runat="server" AssociatedControlID="queryText" Text="Search"/><asp:TextBox ID="queryText" runat="server"CssClass="sf_searchText"></asp:TextBox><input type ="button" id="searchButton"runat="server" onclick="Click();" class="sf_searchSubmit" value="Search"alt="Search"/>
    </fieldset>


    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Dave Ranck
    Dave Ranck avatar
    14 posts
    Registered:
    30 Oct 2003
    02 Feb 2010
    Link to this post
    Hello Radoslav Georgiev,

    Thanks for you reply. I have got the almost search working by setting the EscapeSpecialChars property. If I search for a term with an * at the end of the word, I get the expected results. However if I put an * at the beginning of the word I get the error message:

    "Strange characters should be enclosed between double quotation, modify your query and try again.."

    I have removed both search input validators from the web.config so I'm not sure how this message is being displayed. Is there anywhere else I need to update to make the *searchTerm work?

    Thanks,
    MB
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Feb 2010
    Link to this post
    Hi Mike Brady,

    I am sorry for misleading you on this one. It flew out of my mind that Lucene search queries cannot start with *  or ? symbols. I am afraid there is not an option allow this.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
    Answered
Register for webinar
4 posts, 2 answered