Changed the behavior of the SearchQuery tag. By default only the search keywords (or phrase) are returned. To return the full query (including preset site and file type options) the "type" attribute should be set to "full".
This commit is contained in:
parent
489f08cb62
commit
2242eb2cb2
5 changed files with 83 additions and 32 deletions
|
@ -427,7 +427,7 @@ code {font-size:10pt}
|
|||
<tr>
|
||||
<td>
|
||||
<div align="center">
|
||||
<font size="-1"><b>site</b></font>
|
||||
<font size="-1"><a name="2_1_site"><b>site</b></a></font>
|
||||
</div>
|
||||
</td>
|
||||
<td><font size="-1">Restricts the search to documents within the specfied
|
||||
|
@ -437,7 +437,7 @@ code {font-size:10pt}
|
|||
<tr>
|
||||
<td>
|
||||
<div align="center">
|
||||
<font size="-1"><b>type</b></font>
|
||||
<font size="-1"><a name="2_1_filetype"><b>type</b></a></font>
|
||||
</div>
|
||||
</td>
|
||||
<td><font size="-1">Specifies the <a href="http://www.google.com/help/faq_filetypes.html">file type</a> to be searched. (e.g.: pdf)</font></td>
|
||||
|
@ -675,12 +675,9 @@ code {font-size:10pt}
|
|||
</table>
|
||||
<p>
|
||||
<font size="-1">The <code><google:next/></code> tag is used to
|
||||
|
||||
|
||||
used to display a link to more search results.<br>
|
||||
The <code><google:previous/></code> tag is used to used to display a link
|
||||
to previous search results.</font>
|
||||
|
||||
<p>
|
||||
<font size="-1"><strong>Tag Syntax</strong></font>
|
||||
<p>
|
||||
|
@ -739,11 +736,8 @@ code {font-size:10pt}
|
|||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<font size="-1"></font> <font size="-1">The <code><google:searchComments/></code>
|
||||
tag is used to
|
||||
|
||||
|
||||
display the comments (if any) included with the current result set.</font>
|
||||
<font size="-1">The <code><google:searchComments/></code>
|
||||
tag is used to display the comments (if any) included with the current result set.</font>
|
||||
<p>
|
||||
<a name="2_8" id="2_8"></a>
|
||||
|
||||
|
@ -755,14 +749,15 @@ code {font-size:10pt}
|
|||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<font size="-1"></font> <font size="-1">The <code><google:searchQuery/></code>
|
||||
tag is used to
|
||||
|
||||
|
||||
display the text of the current query.
|
||||
|
||||
<font size="-1">The <code><google:searchQuery/></code> tag is used to display
|
||||
the text of the current query.
|
||||
</font>
|
||||
<p>
|
||||
<font size="-1">The specified search keywords (or phrase) are returned by default.
|
||||
To display the full query (including preset <a href="#2_1_site">site</a> and
|
||||
<a href="#2_1_filetype">file type</a> options), set the <code>type</code> attribute
|
||||
to <code>full</a>.</font>
|
||||
<p>
|
||||
<a name="2_9" id="2_9"></a>
|
||||
|
||||
<table bgcolor="#fff9e4" cellpadding="2" width="100%" border="0">
|
||||
|
@ -773,12 +768,9 @@ code {font-size:10pt}
|
|||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<font size="-1"></font> <font size="-1">The <code><google:searchTime/></code>
|
||||
tag is used to
|
||||
|
||||
|
||||
display the total server time used to return the search results, measured in
|
||||
seconds.</font>
|
||||
<font size="-1">The <code><google:searchTime/></code>
|
||||
tag is used to display the total server time used to return the search results,
|
||||
measured in seconds.</font>
|
||||
<p>
|
||||
<a name="2_10" id="2_10"></a>
|
||||
|
||||
|
@ -790,11 +782,9 @@ code {font-size:10pt}
|
|||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<font size="-1"></font> <font size="-1">The <code><google:searchTips/></code>
|
||||
tag is used to
|
||||
|
||||
|
||||
display the tips (if any) included with the current result set.</font>
|
||||
<font size="-1">The <code><google:searchTips/></code>
|
||||
tag is used to display the tips (if any) included with the current result
|
||||
set.</font>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="cached" id="cached"></a>
|
||||
|
|
|
@ -115,6 +115,7 @@ public class GoogleSearchBean
|
|||
"The authorization key has not been specified.";
|
||||
private GoogleSearch service = null;
|
||||
private GoogleSearchResult result = null;
|
||||
private String keywords = null;
|
||||
private GoogleSearchResultElement elements[] = null;
|
||||
private boolean keySet = false;
|
||||
private int maxResults = 10;
|
||||
|
@ -168,6 +169,26 @@ public class GoogleSearchBean
|
|||
return keySet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the search keywords.
|
||||
*
|
||||
* @param keywords The keywords
|
||||
*/
|
||||
public final void setKeywords(String keywords)
|
||||
{
|
||||
this.keywords = keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keywords.
|
||||
*
|
||||
* @return The keywords value.
|
||||
*/
|
||||
public final String getKeywords()
|
||||
{
|
||||
return this.keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP proxy host, port, user name and password.
|
||||
*
|
||||
|
@ -578,6 +599,10 @@ public class GoogleSearchBean
|
|||
{
|
||||
return String.valueOf(result.getDocumentFiltering());
|
||||
}
|
||||
else if (property.equalsIgnoreCase("searchKeywords"))
|
||||
{
|
||||
return getKeywords();
|
||||
}
|
||||
else if (property.equalsIgnoreCase("searchQuery"))
|
||||
{
|
||||
return result.getSearchQuery();
|
||||
|
|
|
@ -362,6 +362,8 @@ public class Search extends QuerySupport
|
|||
pageContext.getServletContext()
|
||||
.getInitParameter(TagUtility.GOOGLE_PROXY_PASSWORD));
|
||||
|
||||
bean.setKeywords(getQuery());
|
||||
|
||||
bean.getGoogleSearch(getKey(), getSite() + getQuery() + getType(),
|
||||
getStart(), getMaxResults(), getFilter(),
|
||||
getRestrict(), getSafeSearch(), getLr());
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
* Copyright (c) 2002-2003, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
|
@ -20,7 +20,7 @@
|
|||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
|
@ -36,6 +36,8 @@
|
|||
*/
|
||||
package net.thauvin.google.taglibs;
|
||||
|
||||
import net.thauvin.google.TagUtility;
|
||||
|
||||
|
||||
/**
|
||||
* A custom tag used to retrieve the query string of a Google search.
|
||||
|
@ -47,6 +49,28 @@ package net.thauvin.google.taglibs;
|
|||
*/
|
||||
public class SearchQuery extends SearchResultSupport
|
||||
{
|
||||
private String type = null;
|
||||
|
||||
/**
|
||||
* Sets the type attribute
|
||||
*
|
||||
* @param type The new attribute value.
|
||||
*/
|
||||
public final void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release method.
|
||||
*/
|
||||
public void release()
|
||||
{
|
||||
super.release();
|
||||
|
||||
type = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property provided by this tag.
|
||||
*
|
||||
|
@ -54,7 +78,12 @@ public class SearchQuery extends SearchResultSupport
|
|||
*/
|
||||
protected String getPropertyName()
|
||||
{
|
||||
return "searchQuery";
|
||||
if (TagUtility.isValidString(type) && type.equalsIgnoreCase("full"))
|
||||
{
|
||||
return "searchQuery";
|
||||
}
|
||||
|
||||
return "searchKeywords";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -181,7 +181,12 @@
|
|||
<tagclass>net.thauvin.google.taglibs.SearchQuery</tagclass>
|
||||
<bodycontent>empty</bodycontent>
|
||||
<info>Displays the current search query.</info>
|
||||
</tag>
|
||||
<attribute>
|
||||
<name>type</name>
|
||||
<required>false</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
</tag>
|
||||
<!-- SearchResult Tag -->
|
||||
<tag>
|
||||
<name>searchResult</name>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue