[Yanel-commits] rev 44016 -
public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search
michi at wyona.com
michi at wyona.com
Wed Aug 5 15:26:34 CEST 2009
Author: michi
Date: 2009-08-05 15:26:34 +0200 (Wed, 05 Aug 2009)
New Revision: 44016
Modified:
public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java
Log:
content parsing started
Modified: public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java 2009-08-05 13:23:46 UTC (rev 44015)
+++ public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java 2009-08-05 13:26:34 UTC (rev 44016)
@@ -122,7 +122,7 @@
}
/**
- *
+ * @param query Search terms
*/
private Result[] getLocalResults(String query) throws Exception {
if (query != null && query.length() > 0) {
@@ -130,7 +130,8 @@
if (nodes != null && nodes.length > 0) {
Result[] results = new Result[nodes.length];
for (int i = 0; i < nodes.length; i++) {
- results[i] = new Result(nodes[i].getPath(), "TODO: title", "TODO: excerpt", nodes[i].getMimeType(), null);
+ // TODO: Check access policy if user is actually allowed to see this result
+ results[i] = new Result(nodes[i].getPath(), getTitle(nodes[i].getPath(), nodes[i].getInputStream(), nodes[i].getMimeType()), "TODO: excerpt", nodes[i].getMimeType(), null);
//results[i] = new Result(nodes[i].getPath(), null, null, nodes[i].getMimeType(), null);
}
return results;
@@ -188,6 +189,35 @@
}
return null;
}
+
+ /**
+ *
+ */
+ private String getTitle(String path, InputStream in, String mimeType) throws Exception {
+ log.warn("DEBUG: Get title of node: " + path);
+ if (mimeType != null) {
+ // TODO: Allow local tika config (or use one of data repository)
+ org.apache.tika.parser.Parser parser = org.apache.tika.config.TikaConfig.getDefaultConfig().getParser(mimeType);
+ //org.apache.tika.parser.Parser parser = config.getTikaConfig().getParser(mimeType);
+ if (parser != null) {
+ try {
+ java.io.StringWriter writer = new java.io.StringWriter();
+ // NOTE: The tika meta data must not be null, hence we just declare something
+ org.apache.tika.metadata.Metadata tikaMetaData = new org.apache.tika.metadata.Metadata();
+ tikaMetaData.set("yarep:path", path);
+ parser.parse(in, new org.apache.tika.sax.WriteOutContentHandler(writer), tikaMetaData);
+ log.warn("DEBUG: Title: " + writer.toString());
+ } catch (Exception e) {
+ log.error(e, e);
+ }
+ } else {
+ log.error("Tika parser is null!");
+ }
+ } else {
+ log.warn("Node '" + path + "' has no content type and hence will not be parsed re title");
+ }
+ return null;
+ }
}
/**
More information about the Yanel-commits
mailing list