This section provides samples that teach the basic operation and control of the core search control.
setDrawMode()
method of the
GdrawOptions
object.
setResultSetSize()
method of the
GSearchControl
object, or the same method on an individual
searcher object.
setExpandMode()
method of the
GsearcherOptions
object.
GSearchControl
. This sample demonstrates how to
do exactly this. You will see how to initiate a search, respond to
search completion, and generate an HTML representation of a search result.
This section provides samples that demonstrate the use of the search control when placement of result sections or the search form itself is important. For instance, in many blogs, it is common to place the search form in the side bar while placing the search results in the center section of the page. Examples in this section demonstrate how to do this.
setSearchFormRoot()
method of the
GdrawOptions
object. This is a common technique used in blogs
when trying to place the search form in the sidebar while placing the
search results in the main section of the blog.
setRoot()
method of the
GsearcherOptions
object.
This section provides samples that demonstrate the use of the
GlocalSearch
object. The main things demonstrated in these samples
include setting the center point of the object to scope search results
to a particular region, as well as how to use the object as a source
of results to be plotted on a Google Map.
GMap
, a GMap2
,
a GPoint
, and a GLatLng
.
Setting the center point is done using the
setCenterPoint()
method of the
GlocalSearch
object.
.lat
and .lng
properties to create a
GLatLng/GMarker
as well as using the .html
property in order to specify the html of an info window. In addition
to these basics, this sample also demonstrates the use of a searcher outside
of a search control, as well as the use of the GSearchForm
object.
directions
link provides directions from the current center point of the search to the
search result. As an alternate, your application can make visible links
that show directions to/from a user selected location to/from the current
search result. This sample demonstrates how your application can control
which type of driving directions is displayed.
staticMapUrl
property that resolves to
a map image that visually represents the local search result on a map. Using this property
is fast and efficient when all you want to do provide a small thumbnail representation of
the search result. The sample demonstrates the use of this property and related support methods.
This section provides samples that demonstrate the use of the
setSiteRestriction()
method of a searcher to scope
a set of search results to a site, or to a custom search engine.
The GwebSearch
, GblogSearch
, and GnewsSearch
searchers all support this basic method, but only GwebSearch
supports scoping to a custom search engine.
setSiteRestriction()
method of the GwebSearch
, GblogSearch
, and
GnewsSearch
objects. When doing site restricted search, it
is often a good idea to specify a customized label for the search result section
header, and in some cases, perform some custom styling of the search results.
Both of these functions are supported by using the setUserDefinedLabel()
and setUserDefinedClassSuffix()
methods.
setSiteRestriction()
all being made using
a custom search engine id. The sample includes some other concepts
that are not related to site restriction. These include the use of
the GSearchForm
object that is used to drive multiple search
controls and the use of custom CSS directives that restyle portions of
the search control and results.
setSiteRestriction()
for the right hand
side searcher, the code is using the opt_refinement
argument
to further restrict the search results within the custom search engine.
site
and in the crefUrl
property we supply the url of a Custom Search Engine definition file.
This section provides samples that demonstrate the use of search result clipping. This is a feature that allows users to click on a link below a search result and hand that result to the application. In this section, we include a few samples that demonstrate this feature.
setOnKeepHandler()
method of
the search control object. This causes a clickable link to show up
underneath each search result which, when clicked, calls the target
handler. In this sample, the target handle makes a deep clone
of the result's .html
property and then attaches this
onto the current page.
.html
property.
In this case, each time a user clips a search result, a "row" is added
to a spreadsheet and the columns are formed using the .title
,
.streetAddress
, etc. properties. The sample also demonstrates plotting
a "clipped" search result on a map, something that was demonstrated in previous sections
as well.
AJAX Search is a very popular addition to blogs. We have built two sample blogs that demonstrate the use of AJAX Search in both TypePad and in Blogger.
setSearchFormRoot()
.
In this section, we provide links to more advanced code samples that merge several of the concepts demonstrated above into a single sample. Use these samples for ideas, and feel free to borrow liberally.