Author: chathura
Date: Thu Dec 13 21:58:16 2007
New Revision: 11104
Log:
Improving the tag based search.
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/TaggedResourcePath.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/TaggedResourcePath.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/TaggedResourcePath.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/TaggedResourcePath.java
Thu Dec 13 21:58:16 2007
@@ -16,9 +16,13 @@
package org.wso2.registry;
+import java.util.Map;
+import java.util.HashMap;
+
public class TaggedResourcePath {
private String resourcePath;
+ private Map tagCounts = new HashMap();
private long tagCount;
public String getResourcePath() {
@@ -36,4 +40,16 @@
public void setTagCount(long tagCount) {
this.tagCount = tagCount;
}
+
+ public Map getTagCounts() {
+ return tagCounts;
+ }
+
+ public void setTagCounts(Map tagCounts) {
+ this.tagCounts = tagCounts;
+ }
+
+ public void addTagCount(String tag, long count) {
+ tagCounts.put(tag, new Long(count));
+ }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
Thu Dec 13 21:58:16 2007
@@ -34,9 +34,7 @@
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
/**
* JDBC based implementation of the Registry. This will be used mostly as the
back-end by other
@@ -506,18 +504,28 @@
public TaggedResourcePath[] getResourcePathsWithTag(String tag) throws
RegistryException {
// break the tags from spaces
- String[] tags = tag.split(" ");
+ String[] tags = tag.trim().split(" ");
- List pathList = new ArrayList();
+ //List pathList = new ArrayList();
+ List taggedPaths = new ArrayList();
Connection conn = connectionFactory.getConnection();
try {
- for (int i = 0; i < tags.length; i++) {
- if (tags[i].length() == 0 || tags[i].equals(" ")) {
- continue;
+
+ List pathList = tagsDAO.getPathsWithAnyTag(tags, conn);
+ Iterator iPaths = pathList.iterator();
+ while (iPaths.hasNext()) {
+ String path = (String) iPaths.next();
+
+ TaggedResourcePath taggedResourcePath = new
TaggedResourcePath();
+ taggedResourcePath.setResourcePath(path);
+
+ for (int i = 0; i < tags.length; i++) {
+ long count = tagsDAO.getTagCount(path, tags[i], conn);
+ taggedResourcePath.addTagCount(tags[i], count);
}
- pathList.addAll(tagsDAO.getTaggedPaths(tags[i], conn));
+ taggedPaths.add(taggedResourcePath);
}
} catch (SQLException e) {
@@ -535,7 +543,7 @@
}
return
- (TaggedResourcePath[]) pathList.toArray(new
TaggedResourcePath[pathList.size()]);
+ (TaggedResourcePath[]) taggedPaths.toArray(new
TaggedResourcePath[taggedPaths.size()]);
}
/**
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
Thu Dec 13 21:58:16 2007
@@ -142,6 +142,51 @@
return (String[]) tagList.toArray(new String[tagList.size()]);
}
+ public List getPathsWithAnyTag(String[] tags, Connection conn) throws
SQLException {
+
+ String sql = null;
+ if (tags.length == 1) {
+ sql = "SELECT R.PATH FROM ARTIFACTS R, TAGS T WHERE R.AID=T.AID
AND T.TAG_NAME=?";
+ } else if (tags.length == 2) {
+ sql = "SELECT R.PATH FROM ARTIFACTS R, TAGS T WHERE R.AID=T.AID
AND (T.TAG_NAME=? OR T.TAG_NAME=?)";
+ } else if (tags.length == 3) {
+ sql = "SELECT R.PATH FROM ARTIFACTS R, TAGS T WHERE R.AID=T.AID
AND (T.TAG_NAME=? OR T.TAG_NAME=? OR T.TAG_NAME=?)";
+ }
+
+ PreparedStatement s = conn.prepareStatement(sql);
+
+ for (int i = 0; i < tags.length; i++) {
+ s.setString(i + 1, tags[i]);
+ }
+
+ List resourcePaths = new ArrayList();
+ ResultSet results = s.executeQuery();
+ while (results.next()) {
+ resourcePaths.add(results.getString(DatabaseConstants.PATH_FIELD));
+ }
+ return resourcePaths;
+ }
+
+ public List getPathsWithAllTags(String[] tags, Connection conn) throws
SQLException {
+ return null;
+ }
+
+ public long getTagCount(String path, String tag, Connection conn) throws
SQLException {
+
+ String sql = "SELECT COUNT(TN.TAG_NAME) FROM ARTIFACTS A, TAGS TN
WHERE A.PATH=? AND TN.TAG_NAME=? AND TN.AID=A.AID GROUP BY A.PATH";
+
+ PreparedStatement s = conn.prepareStatement(sql);
+ s.setString(1, path);
+ s.setString(2, tag);
+
+ ResultSet result = s.executeQuery();
+ if (result.next()) {
+ return result.getLong(1);
+ }
+
+ return 0;
+ }
+
public List getTaggedPaths(String tag, Connection conn) throws
SQLException {
String sql = "SELECT A.PATH, COUNT(TN.TAG_NAME) FROM ARTIFACTS A, TAGS
TN WHERE TN.TAG_NAME=? AND TN.AID=A.AID GROUP BY A.PATH";
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
Thu Dec 13 21:58:16 2007
@@ -175,7 +175,7 @@
public void setTags(String tags) {
this.tags = tags;
- String[] tagParts = tags.split(" ");
+ String[] tagParts = tags.trim().split(" ");
if (tagParts.length > 0) {
tag1 = tagParts[0];
}
@@ -217,7 +217,7 @@
if (queryPath == null) {
- StringBuffer buf = new StringBuffer("/queries/advanced");
+ StringBuffer buf = new StringBuffer("/system/queries/advanced");
if (resourceName != null && resourceName.length() > 0) {
buf.append("1");
@@ -404,7 +404,7 @@
String fromTags = "";
String tagsQuery = "";
if (tag1 != null && tag1.length() > 0) {
- String[] tag = new String[] {tag1, tag2, tag3};
+ String[] tag = tags.trim().split(" ");
if (tag.length > 0) {
fromTags = ", TAGS T";
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev