Author: ssmalamb
Date: 2007-02-14 17:23:12 +0100 (Wed, 14 Feb 2007)
New Revision: 4442
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/BlocketSearchConfiguration.java
Log:
changed from properites file format to xml format for commonly used search
words for blocket.se
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
===================================================================
---
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
2007-02-14 15:44:08 UTC (rev 4441)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/SearchModeFactory.java
2007-02-14 16:23:12 UTC (rev 4442)
@@ -108,7 +108,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-
/**
* @author <a href="mailto:[EMAIL PROTECTED]>mick</a>
* @version <tt>$Id$</tt>
@@ -561,25 +560,69 @@
}
+// if(sc instanceof BlocketSearchConfiguration)
+// {
+// final BlocketSearchConfiguration bsc =
(BlocketSearchConfiguration)sc;
+// /**
+// * Read blocket.se properties.
+// */
+// final Map<String,String> blocketmap = new
HashMap<String,String>();
+// Properties props = new Properties();
+// PropertiesLoader loader=
UrlResourceLoader.newPropertiesLoader(cxt, bsc.getBlocketConfigFileName(),
props);
+// loader.abut();
+//
+// /**
+// * Put properties in a map
+// */
+// for (Object value : props.values()) {
+// final String field[] = ((String)value).split(";");
+// if (field.length == 2) {
+// blocketmap.put(field[0], field[1]);
+// }
+// }
+// bsc.setBlocketMap(blocketmap);
+// }
+
if(sc instanceof BlocketSearchConfiguration)
{
final BlocketSearchConfiguration bsc =
(BlocketSearchConfiguration)sc;
/**
- * Läser in blocket specifika properties.
+ * Read blocket.se properties.
*/
+
+
+// configuration files
+ final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ final DocumentBuilder builder =
factory.newDocumentBuilder();
+ DocumentLoader loader =
UrlResourceLoader.newDocumentLoader(cxt, bsc.getBlocketConfigFileName(),
builder);
+
final Map<String,String> blocketmap = new
HashMap<String,String>();
- Properties props = new Properties();
- PropertiesLoader loader=
UrlResourceLoader.newPropertiesLoader(cxt, bsc.getBlocketConfigFileName(),
props);
+// PropertiesLoader loader=
UrlResourceLoader.newPropertiesLoader(cxt, , props);
loader.abut();
+ final Document doc = loader.getDocument();
+ final Element root = doc.getDocumentElement();
+
+ // loop through words.
+ final NodeList wordList =
root.getElementsByTagName("word");
+
+ for (int i = 0; i < wordList.getLength(); ++i) {
+ final Element wordElement = (Element) wordList.item(i);
+ final String cid = wordElement.getAttribute("id");
+ final String catName =
wordElement.getAttribute("category");
+ final String word = wordElement.getTextContent();
+ blocketmap.put(word, cid+":"+catName);
+ System.out.println("xml: "+word +" "+cid+":"+catName);
+ }
/**
- * Lägger properties i en Map för snabbare åtkomst.
+ * Put properties in a map
*/
- for (Object value : props.values()) {
- final String field[] = ((String)value).split(";");
- if (field.length == 2) {
- blocketmap.put(field[0], field[1]);
- }
- }
+// for (Object value : props.values()) {
+// final String field[] = ((String)value).split(";");
+// if (field.length == 2) {
+// blocketmap.put(field[0], field[1]);
+// }
+// }
bsc.setBlocketMap(blocketmap);
}
@@ -587,7 +630,7 @@
final VehicleSearchConfiguration vsc =
(VehicleSearchConfiguration)sc;
/**
- * Läser in Vehicle search specifika properties.
+ * Read vehicle specific properties for bytbil.com and
blocket.se
*/
final Set<String> accessoriesSet = new HashSet<String>();
Properties props = new Properties();
@@ -600,13 +643,16 @@
carLoader.abut();
/**
- * Lägger properties i ett Set och en Map för snabbare
åtkomst.
+ * Put properties in a set
*/
for (Object value : props.values()) {
accessoriesSet.add((String)value);
}
vsc.setAccessoriesSet(accessoriesSet);
+ /**
+ * Put properties in a map
+ */
for (Object value : carProps.values()) {
final String field[] = ((String)value).split(":"); //
Ignore the key, the value is key/value tuple, ugly but it works,
if (field.length == 2) { //
example: property1963=volvo p 1800:volvo;p 1800
@@ -802,6 +848,9 @@
throw new InfrastructureException(ex);
} catch (InvocationTargetException ex) {
throw new InfrastructureException(ex);
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ throw new InfrastructureException(e);
}
}
Modified:
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/BlocketSearchConfiguration.java
===================================================================
---
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/BlocketSearchConfiguration.java
2007-02-14 15:44:08 UTC (rev 4441)
+++
trunk/core-api/src/main/java/no/schibstedsok/searchportal/mode/config/BlocketSearchConfiguration.java
2007-02-14 16:23:12 UTC (rev 4442)
@@ -8,34 +8,35 @@
* Configuration for the blocket command.
*/
public class BlocketSearchConfiguration extends AbstractSearchConfiguration {
-
+
private Map BLOCKETMAP;
- private static final String BLOCKET_CONFIGURATION_FILE =
"blocket.properties";
-
+ private static final String BLOCKET_CONFIGURATION_FILE =
"blocket.properties";
+ private static final String BLOCKET_SEARCH_WORDS_FILE =
"blocket_search_words.xml";
+
/**
* Creates a new instance of this search configuration.
*/
public BlocketSearchConfiguration(final SearchConfiguration sc) {
super(sc);
-
+
}
-
+
public String getBlocketConfigFileName(){
- return BLOCKET_CONFIGURATION_FILE;
+ return BLOCKET_SEARCH_WORDS_FILE;
}
-
+
public Map getBlocketMap()
{
return BLOCKETMAP;
}
-
-
+
+
public void setBlocketMap(Map bmap)
{
-
+
BLOCKETMAP=bmap;
-
+
}
-
+
}
-
+
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits