How to Replace CS Search with Google Custom Search?

rated by 0 users
This post has 13 Replies | 6 Followers

Top 200 Contributor
Posts 125
Points 1,755
Khoai Posted: Thu, Jul 31 2008 12:11 AM

Due to limmited database I want to Disable CS Search and use Google Custom Search for my site instead. In Hawaii theme I tried to edit the master.master and remove the CS Search Code then paste the Google Search Code. However there was still some error. Any one please instruct me where to edit CS Code to use Googel Search for my site

Thank you,

Learning English Online

  • | Post Points: 20
Top 10 Contributor
Posts 2,423
Points 19,635
MVPs
Nick replied on Thu, Jul 31 2008 4:15 PM

In the masterpage don't remove the CS Search, just set the placehold to be invisible (Visible="false").  Then add your own code in.

Hawaii has the search box referenced on other master pages which is why you get the error.

  • | Post Points: 20
Top 200 Contributor
Posts 125
Points 1,755
Khoai replied on Thu, Jul 31 2008 10:37 PM

Nick,

I have replaced the code but the google search didn't work on CS. When I press the Search button, the page only refresh and nothing happen.

Learning English Online

  • | Post Points: 20
Top 10 Contributor
Posts 2,423
Points 19,635
MVPs
Nick replied on Fri, Aug 1 2008 7:58 AM

This is because the google code uses a form.  ASP.net uses the form for postback info.

So what you do is use javascript, and remove the form.

<input type="text" id="query" name="query" /><input type="button" value="Search" onclick="location.href='http://www.google.com/search?q=' + document.getElementById('query').value + ' site:yourdomainname.com';" />

  • | Post Points: 50
Top 200 Contributor
Posts 125
Points 1,755
Khoai replied on Fri, Aug 1 2008 8:23 AM

Nick,

I still get error, please tell me how to change this code:

<style type="text/css">
@import url(http://www.google.com/cse/api/branding.css);
</style>
<div class="cse-branding-bottom" style="background-color:#FFFFFF;color:#000000">
  <div class="cse-branding-form">
    <form action="http://edu.net.vn/search/SearchResults.aspx" id="cse-search-box">
      <div>
        <input type="hidden" name="cx" value="partner-pub-4834229009304130:fszplsaxb11t" />
        <input type="hidden" name="cof" value="FORID:10" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="25" />
        <input type="submit" name="sa" value="Search" />
      </div>
    </form>
  </div>
  <div class="cse-branding-logo">
    <img src="http://www.google.com/images/poweredby_transparent/poweredby_FFFFFF.gif" alt="Google" />
  </div>
  <div class="cse-branding-text">
    Custom Search
</div>

Thank you very much!

Learning English Online

  • | Post Points: 5
Top 200 Contributor
Posts 125
Points 1,755
Khoai replied on Fri, Aug 1 2008 8:33 AM

Nick,

I still get error. Please tell me how to change this code bellow:

<style type="text/css">
@import url(http://www.google.com/cse/api/branding.css);
</style>
<div class="cse-branding-bottom" style="background-color:#FFFFFF;color:#000000">
  <div class="cse-branding-form">
    <form action=".../search/SearchResults.aspx" id="cse-search-box">
      <div>
        <input type="hidden" name="cx" value="partner-pub-4834229009304130:fszplsaxb10t" />
        <input type="hidden" name="cof" value="FORID:10" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="25" />
        <input type="submit" name="sa" value="Search" />
      </div>
    </form>
  </div>
  <div class="cse-branding-logo">
    <img src="http://www.google.com/images/poweredby_transparent/poweredby_FFFFFF.gif" alt="Google" />
  </div>
  <div class="cse-branding-text">
    Custom Search
</div>

Learning English Online

  • | Post Points: 5
Top 10 Contributor
Male
Posts 2,364
Points 15,695
MVPs
Dave replied on Fri, Aug 1 2008 10:51 AM

Don't forget to remove the SearchBarrel stuff in communityserver_override.config too.

  <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='ForumsIndexing']" mode = "remove" />
  <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='WeblogIndexing']" mode = "remove" />
  <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='GalleryIndexing']" mode = "remove" />
  <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='FilesIndexing']" mode = "remove" />

  <Override xpath = "/CommunityServer/SearchBarrel" mode = "remove" />

  • | Post Points: 50
Top 200 Contributor
Posts 125
Points 1,755
Khoai replied on Sat, Aug 2 2008 4:19 AM

Please chang this code to Javascript for me, I tried but the search still not works

<form action="http://www.google.com.vn/cse" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-4834229009304566:sn6gj8-9y5p" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>

Learning English Online

  • | Post Points: 5
Not Ranked
Posts 3
Points 30
ThaiYen replied on Sat, Aug 2 2008 4:24 AM

Please help me to change this code to javascript. I followed Nick instruction but the search still not working

<form action="http://www.google.com.vn/cse" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-4834229009304130:sn6gj8-9y5p" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Tìm kiếm" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=vi"></script>

  • | Post Points: 5
Top 200 Contributor
Posts 125
Points 1,755
Khoai replied on Wed, Aug 6 2008 11:36 AM

Thank to Nick and Dave Instruction I have replaced CS Search with Googe Search. However, I still facing some problems as follow:

  1. When I type the words for searching in the search box I have to click on Search button to make search. If I juste enter as search on Google the page only refreshing.
  2. To remove the SearchBarrel operation to free the database I have created a CommunityServer_Override.config file as bellow:

<?xml version="1.0" encoding="utf-8" ?> 
<Overrides>

   
   
    <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='ForumsIndexing']" mode = "remove" />
    <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='WeblogIndexing']" mode = "remove" />
    <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='MediaGalleryIndexing']" mode = "remove" />
    <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='HubIndexing']" mode = "remove" />
   
    <Override xpath = "/CommunityServer/Tasks/Threads/Thread/task[@name='Emails']" mode = "remove" />
  <Override xpath = "/CommunityServer/SearchBarrel" mode = "remove" />
   

   
</Overrides>

When I browse my site I got this error:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

 

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

 

Stack Trace:

 

[NullReferenceException: Object reference not set to an instance of an object.]

   CommunityServer.Components.SearchBarrel.SearchBarrelProvider..cctor() +71

 

[TypeInitializationException: The type initializer for 'CommunityServer.Components.SearchBarrel.SearchBarrelProvider' threw an exception.]

 

[TargetInvocationException: Exception has been thrown by the target of an invocation.]

   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0

   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +103

   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +268

   System.Activator.CreateInstance(Type type, Boolean nonPublic) +66

   CommunityServer.Components.SingletonProviderHelper.LoadInstance(String ProviderKey, Type defaultType) +81

   CommunityServer.Components.SearchProvider..cctor() +13

 

[TypeInitializationException: The type initializer for 'CommunityServer.Components.SearchProvider' threw an exception.]

   CommunityServer.Components.SearchProvider.Instance() +0

   CommunityServer.Controls.SearchForm.DataBind() +61

   CommunityServer.Controls.WrappedFormBase.OnLoad(EventArgs e) +25

   System.Web.UI.Control.LoadRecursive() +47

   System.Web.UI.Control.LoadRecursive() +131

   System.Web.UI.Control.LoadRecursive() +131

   System.Web.UI.Control.LoadRecursive() +131

   System.Web.UI.Control.LoadRecursive() +131

   System.Web.UI.Control.LoadRecursive() +131

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

Please help me to solve the problems

Thanks,

 

Learning English Online

  • | Post Points: 20
Top 10 Contributor
Posts 2,423
Points 19,635
MVPs
Nick replied on Wed, Aug 6 2008 11:43 AM

it make it capture the return button you'll need to search for "Javascript key events enter".  It should tell you how to add an onkeydown function to the textbox to init the search

  • | Post Points: 20
Top 200 Contributor
Posts 125
Points 1,755
Khoai replied on Sun, Sep 21 2008 3:46 AM

Nick,

Please take a look and tell me what wrong which this code:

<!-- Search Google -->
                <CENTER>
            <SCRIPT language=JavaScript>
            </SCRIPT>
               <div align="center">
                <input type="text" name="q" id="cse-search-box" size="25" />     
                <input type="button" name="sa"
            onclick="location.href='http://www.google.com.vn/cse?q=' + document.getElementById('cse-search-box').value
             + '&amp;cx=partner-pub-4834229009304142:4a65sb-mewc&amp;&amp;ie=UTF-8';"function DetectEnterPressed(e) {
var characterCode
if(e && e.which){ // NN4 specific code
e = e
characterCode = e.which
}
else {
e = event
characterCode = e.keyCode // IE specific code
}
if (characterCode == 13) return true // Enter key is 13
else return false
} value="Search" />
                  </div>
                  </CENTER>
<!-- Search Google -->

Learning English Online

  • | Post Points: 20
Top 500 Contributor
Posts 48
Points 760

I spent a lot of time trying to do the exact same thing and came up with a bit of a compromise. On all the pages that did not commit information to the database; I was able to replace the default <form> tag used by CS with the Google Form tag (keep runat="server"  outta there!). On all other pages I placed a Google Search graphic that pushed users to the search page when clicked. You can achieve this through the use of multiple master pages, and so far I'm thinking it works pretty well.

  • | Post Points: 20
Not Ranked
Posts 17
Points 205

Heya,

I've made my own SearchProvider by inheriting from SearchBarrelProvider in CommunityServer.Components.SearchBarrel in my own project, then changed the reference in communityserver.config thusly:

        <!--
        <add
            name =     "SearchProvider"
            type = "CommunityServer.Components.SearchBarrel.SearchBarrelProvider, CommunityServer.Components.SearchBarrel" />
        -->
        <add
            name =     "SearchProvider"
                type = "HillsKBExtensions.HillsSearchBarrelProvider, HillsKBExtensions" />

Yes, I'm still using CommunityServer2007, but that's the best I have access to currently.  Could someone tell me why I get the "Oops!" page, & see a record in the cs_exceptions with the following

Exception:  System.Exception: Provider Type HillsKBExtensions.HillsSearchBarrelProvider, HillsKBExtensions could not be loaded     at CommunityServer.Components.SingletonProviderHelper.LoadInstance(String ProviderKey, Type defaultType)     at CommunityServer.Components.SearchProvider..cctor()

ExceptionMessage:  The type initializer for 'CommunityServer.Components.SearchProvider' threw an exception.

 

So far, I've used this pattern of inheriting & replacing references in the communityserver.config, & it has worked.  Additionally, from what I've learned/read, it's better to *not* modify the source, but make as many changes as possible in a separate project.  This is the 1st time this has happened, & I can't figure why...

Help me, Obiwan Kenobi, you're my only hope...

- O8

 

Page 1 of 1 (14 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com