Author: ssmaeklu
Date: 2007-06-26 15:35:38 +0200 (Tue, 26 Jun 2007)
New Revision: 5431
Modified:
branches/2.14/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/PicSearchCommand.java
branches/2.14/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/PictureCommandConfig.java
Log:
Added option for new feature in picsearch API. Domain boost. Deprecated country
option
Modified:
branches/2.14/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/PicSearchCommand.java
===================================================================
---
branches/2.14/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/PicSearchCommand.java
2007-06-26 12:47:12 UTC (rev 5430)
+++
branches/2.14/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/PicSearchCommand.java
2007-06-26 13:35:38 UTC (rev 5431)
@@ -65,63 +65,63 @@
*/
public ResultList<? extends ResultItem> execute() {
- String query = getTransformedQuery();
- final PictureCommandConfig psConfig = (PictureCommandConfig)
context.getSearchConfiguration();
+ final PictureCommandConfig cfg = (PictureCommandConfig)
context.getSearchConfiguration();
try {
- query = URLEncoder.encode(query, "utf-8");
- } catch (UnsupportedEncodingException e) {
- LOG.error(e);
- }
- String topDomainBoost = "";
+ final String query = URLEncoder.encode(getTransformedQuery(),
"utf-8");
+ final String urlBoost = tldb.toString();
- try {
- topDomainBoost = URLEncoder.encode(tldb.length() > 0 ?
tldb.toString() : psConfig.getCountry(), "utf-8");
- } catch (UnsupportedEncodingException e) {
- LOG.error(e);
- }
+ final String cfgBoost = ! "".equals(cfg.getDomainBoost()) ?
cfg.getDomainBoost() : cfg.getCountry();
- final String url = MessageFormat.format(REQ_URL_FMT,
- topDomainBoost,
- psConfig.getFilter(),
- psConfig.getCustomerId(),
- psConfig.getResultsToReturn(),
- query,
- getCurrentOffset(1),
- siteFilter);
+ // The boost can eiter be from the URL or from the configuration.
+ final String boost = URLEncoder.encode(urlBoost.length() > 0 ?
urlBoost : cfgBoost, "utf-8");
- DUMP.info("Using " + url);
+ final String url = MessageFormat.format(REQ_URL_FMT,
+ boost,
+ cfg.getFilter(),
+ cfg.getCustomerId(),
+ cfg.getResultsToReturn(),
+ query,
+ getCurrentOffset(1),
+ siteFilter);
- final BasicResultList<ResultItem> searchResult = new
BasicResultList<ResultItem>();
+ DUMP.info("Using " + url);
- if (port > 0){
+ final BasicResultList<ResultItem> searchResult = new
BasicResultList<ResultItem>();
- final Document doc = doSearch(url);
+ if (port > 0){
- if (doc != null) {
+ final Document doc = doSearch(url);
- final Element resultElement = doc.getDocumentElement();
+ if (doc != null) {
-
searchResult.setHitCount(Integer.parseInt(resultElement.getAttribute("hits")));
+ final Element resultElement = doc.getDocumentElement();
- final NodeList list =
resultElement.getElementsByTagName("image");
- for (int i = 0; i < list.getLength(); i++) {
+
searchResult.setHitCount(Integer.parseInt(resultElement.getAttribute("hits")));
- final Element picture = (Element) list.item(i);
+ final NodeList list =
resultElement.getElementsByTagName("image");
+ for (int i = 0; i < list.getLength(); i++) {
- final BasicResultItem item = new BasicResultItem();
+ final Element picture = (Element) list.item(i);
- for (final Map.Entry<String,String> entry :
psConfig.getResultFields().entrySet()) {
+ final BasicResultItem item = new BasicResultItem();
- item.addField(entry.getValue(),
picture.getAttribute(entry.getKey()));
+ for (final Map.Entry<String,String> entry :
cfg.getResultFields().entrySet()) {
+
+ item.addField(entry.getValue(),
picture.getAttribute(entry.getKey()));
+ }
+ searchResult.addResult(item);
+
}
- searchResult.addResult(item);
-
}
}
+
+ return searchResult;
+
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
}
- return searchResult;
}
/**
Modified:
branches/2.14/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/PictureCommandConfig.java
===================================================================
---
branches/2.14/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/PictureCommandConfig.java
2007-06-26 12:47:12 UTC (rev 5430)
+++
branches/2.14/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/PictureCommandConfig.java
2007-06-26 13:35:38 UTC (rev 5431)
@@ -30,6 +30,7 @@
private String filter;
private String customerId;
private String site;
+ private String domainBoost;
/**
* Getter for property key for queryServerUrl.
@@ -64,7 +65,7 @@
}
/**
- *
+ * @deprecated use domainBoost instead. A boost of 50 is equivalent to
setting the country parameter
* @return
*/
public String getCountry() {
@@ -133,6 +134,24 @@
this.site = site;
}
+ /**
+ * Returns the domain boost to use.
+ *
+ * @return the domain boost.
+ */
+ public String getDomainBoost() {
+ return domainBoost;
+ }
+
+ /**
+ * Sets the domain boost. Example of domain boost string:
se=100,nu=100,dk=50.
+ *
+ * @param domainBoost the domain boost string.
+ */
+ public void setDomainBoost(String domainBoost) {
+ this.domainBoost = domainBoost;
+ }
+
@Override
public CommandConfig readSearchConfiguration(
final Element element,
@@ -146,9 +165,11 @@
AbstractDocumentFactory.fillBeanProperty(this, inherit, "filter",
ParseType.String, element, "medium");
AbstractDocumentFactory.fillBeanProperty(this, inherit, "customerId",
ParseType.String, element, "558735");
AbstractDocumentFactory.fillBeanProperty(this, inherit, "site",
ParseType.String, element, "");
+ AbstractDocumentFactory.fillBeanProperty(this, inherit, "domainBoost",
ParseType.String, element, "");
LOG.debug("customerid " + getCustomerId());
return this;
}
+
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits