[Registry-dev] svn commit r19896 - in trunk/registry/modules: core/src/main/java/org/wso2/registry/jdbc core/src/main/java/org/wso2/registry/jdbc/indexing core/src/main/java/org/wso2/registry/jdbc/queries extensions/src/org/wso2/registry/handlers extensions/test/org/wso2/registry/jdbc webapps/src/main/java/org/wso2/registry/web webapps/src/main/java/org/wso2/registry/web/actions webapps/src/main/java/org/wso2/registry/web/actions/utils webapps/src/main/webapp/admin webapps/src/main/webapp/admin/js

kalani at wso2.com kalani at wso2.com
Wed Jul 23 03:27:51 PDT 2008


Author: kalani
Date: Wed Jul 23 03:27:51 2008
New Revision: 19896
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19896

Log:
Combined the content search functionality with advanced search. Implemented document deletion from the index.


Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessor.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java
   trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java
   trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AdvancedSearchAction.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
   trunk/registry/modules/webapps/src/main/webapp/admin/advanced-search.jsp
   trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/BasicRegistry.java	Wed Jul 23 03:27:51 2008
@@ -644,7 +644,7 @@
 
         Resource query = get(path);
 
-        return queryProcessorManager.executeQuery(query, parameters);
+        return queryProcessorManager.executeQuery(this, query, parameters);
     }
 
 

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/indexing/Indexer.java	Wed Jul 23 03:27:51 2008
@@ -44,44 +44,68 @@
         String path = requestContext.getResourcePath().getPath();
         RAMDirectory ramDir = RegistryContext.getSingleton().getRamDir();
 
-        try{
+        try {
 
-            if(resourceDAO.resourceExists(path)){
-            id = resourceDAO.getResourceID(path, RegistryContext.getSingleton().getDataSource().getConnection());
-            if(IndexReader.indexExists(ramDir)){
-            IndexReader reader = IndexReader.open(ramDir);
-                Term term = new Term("id",id);
-                if(reader.docFreq(term) > 0){
-                reader.deleteDocuments(term);
+            if (resourceDAO.resourceExists(path)) {
+                id = resourceDAO.getResourceID(path, RegistryContext.getSingleton().getDataSource().getConnection());
+                if (IndexReader.indexExists(ramDir)) {
+                    IndexReader reader = IndexReader.open(ramDir);
+                    Term term = new Term("id", id);
+                    if (reader.docFreq(term) > 0) {
+                        reader.deleteDocuments(term);
+                    }
+                    reader.close();
                 }
-                reader.close();
-            }
-        }else{
+            } else {
                 id = resource.getId();
             }
             //InputStream is = resource.getContentStream();
-           // DataInputStream din = new DataInputStream(is);
-           // while((line=din.readLine()) != null){
-           //     sb.append(line+"\n");
-           // }
-           // is.close();
-            byte [] content = (byte [])resource.getContent();
+            // DataInputStream din = new DataInputStream(is);
+            // while((line=din.readLine()) != null){
+            //     sb.append(line+"\n");
+            // }
+            // is.close();
+            byte[] content = (byte[]) resource.getContent();
             //resource.setContentStream(null);
 
             Document document = new Document();
             document.add(new Field("id", id, Field.Store.YES, Field.Index.TOKENIZED));
-            document.add(new Field("content", new String(content),Field.Store.NO, Field.Index.TOKENIZED));
+            document.add(new Field("content", new String(content), Field.Store.NO, Field.Index.TOKENIZED));
 
-            IndexWriter writer = new IndexWriter(RegistryContext.getSingleton().getRamDir(),new StandardAnalyzer());
+            IndexWriter writer = new IndexWriter(RegistryContext.getSingleton().getRamDir(), new StandardAnalyzer());
             writer.addDocument(document);
             writer.optimize();
             writer.close();
-        }catch(CorruptIndexException e){
+        } catch (CorruptIndexException e) {
             e.printStackTrace();
-        }catch(IOException e){
+        } catch (IOException e) {
             e.printStackTrace();
-        }catch(SQLException e){
+        } catch (SQLException e) {
             throw new RegistryException(e.getMessage());
         }
     }
+
+    public void deleteFromIndex(RequestContext requestContext) throws RegistryException {
+        String id;
+
+        RAMDirectory ramDir = RegistryContext.getSingleton().getRamDir();
+
+        Resource resource = requestContext.getResource();
+        id = resource.getId();
+
+        try {
+            IndexReader reader = IndexReader.open(ramDir);
+            Term term = new Term("id", id);
+            if (reader.docFreq(term) > 0) {
+                reader.deleteDocuments(term);
+            }
+            reader.close();
+        } catch (CorruptIndexException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+
+    }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessor.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessor.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessor.java	Wed Jul 23 03:27:51 2008
@@ -17,8 +17,9 @@
 package org.wso2.registry.jdbc.queries;
 
 import org.wso2.registry.Collection;
-import org.wso2.registry.exceptions.RegistryException;
+import org.wso2.registry.Registry;
 import org.wso2.registry.Resource;
+import org.wso2.registry.exceptions.RegistryException;
 import org.wso2.registry.users.UserRealm;
 
 import javax.sql.DataSource;
@@ -65,6 +66,6 @@
      * @throws org.wso2.registry.exceptions.RegistryException QueryProcessor impl should handle all exceptions and throw
      * RegisrtyException if the exception has to propagated to the client.
      */
-    public abstract Collection executeQuery(Resource query, Map parameters)
+    public abstract Collection executeQuery(Registry registry, Resource query, Map parameters)
             throws RegistryException;
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/QueryProcessorManager.java	Wed Jul 23 03:27:51 2008
@@ -76,7 +76,7 @@
         return (QueryProcessor)queryProcessors.get(queryType);
     }
 
-    public Collection executeQuery(Resource queryResource, Map parameters) throws RegistryException {
+    public Collection executeQuery(Registry registry, Resource queryResource, Map parameters) throws RegistryException {
 
         if (queryResource.getMediaType() == null || queryResource.getMediaType().length() == 0) {
             String msg = "Failed to execute query at path: " + queryResource.getPath() +
@@ -93,6 +93,6 @@
             throw new RegistryException(msg);
         }
 
-        return queryProcessor.executeQuery(queryResource, parameters);
+        return queryProcessor.executeQuery(registry, queryResource, parameters);
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java	Wed Jul 23 03:27:51 2008
@@ -45,9 +45,11 @@
         super(dataSource, realm);
     }
 
-    public Collection executeQuery(Resource query, Map parameters) throws RegistryException {
+    public Collection executeQuery(Registry registry, Resource query, Map parameters) throws RegistryException {
 
         Connection conn = null;
+        String keywords = null;
+        String [] contentResult = null;
 
         try {
 
@@ -57,7 +59,8 @@
             PreparedStatement s = conn.prepareStatement(sqlString);
 
             if (parameters != null) {
-
+                keywords = (String)parameters.get("content");
+                parameters.remove("content");
                 Iterator iParams = parameters.keySet().iterator();
                 while (iParams.hasNext()) {
                     String paramNumber = (String)iParams.next();
@@ -71,6 +74,9 @@
             }
 
             ResultSet results = s.executeQuery();
+            if(keywords != null && !keywords.equals("")){
+                contentResult = (String []) registry.searchContent(keywords).getContent();
+            }
 
             String resultType = query.getProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME);
 
@@ -79,7 +85,7 @@
                 // Result is a normal resource, which is stored in the Resources table or a collection
                 // of normal resources.
 
-                return fillResourcesCollection(results, conn);
+                return fillResourcesCollection(contentResult, results, conn);
 
             } else if (resultType.equals(RegistryConstants.COMMENTS_RESULT_TYPE)) {
 
@@ -125,17 +131,28 @@
         }
     }
 
-    private Collection fillResourcesCollection(ResultSet results, Connection conn)
+    private Collection fillResourcesCollection(String [] contentResult, ResultSet results, Connection conn)
             throws SQLException {
 
         // Result is a normal resource, which is stored in the Resources table or a collection
         // of normal resources.
 
         List pathList = new ArrayList();
-
+        if (contentResult != null){
         while (results.next()) {
             String path = results.getString(DatabaseConstants.PATH_FIELD);
+            for(int i=0; i<contentResult.length; i++){
+                if(path.equals(contentResult[i])){
             pathList.add(path);
+                    break;
+                }
+            }
+        }
+        }else{
+            while (results.next()) {
+            String path = results.getString(DatabaseConstants.PATH_FIELD);
+            pathList.add(path);
+        }
         }
 
         String[] paths = (String[])pathList.toArray(new String[pathList.size()]);

Modified: trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java	(original)
+++ trunk/registry/modules/extensions/src/org/wso2/registry/handlers/IndexingHandler.java	Wed Jul 23 03:27:51 2008
@@ -35,6 +35,7 @@
     }
 
     public void delete(RequestContext requestContext) throws RegistryException {
+        new Indexer().deleteFromIndex(requestContext);
     }
 
     public void putChild(RequestContext requestContext) throws RegistryException {

Modified: trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java	(original)
+++ trunk/registry/modules/extensions/test/org/wso2/registry/jdbc/IndexingTest.java	Wed Jul 23 03:27:51 2008
@@ -50,6 +50,12 @@
 
         assertEquals("Search should not return results when non existing keywords are submitted.",0, paths2.length);
 
+        registry.delete(r6Path);
+        Collection collection3 = registry.searchContent("r6");
+        String [] paths3 = (String [])collection3.getContent();
+
+        assertEquals("Search should not return results for a deleted document", 0, paths3.length);
+
     }
 
 

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java	Wed Jul 23 03:27:51 2008
@@ -1137,6 +1137,7 @@
         advancedSearchAction.setCommentWords(request.getParameter("commentWords"));
         advancedSearchAction.setPropertyName(request.getParameter("propertyName"));
         advancedSearchAction.setPropertyValue(request.getParameter("propertyValue"));
+        advancedSearchAction.setContent(request.getParameter("content"));
 
         try {
             advancedSearchAction.execute(request);

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AdvancedSearchAction.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AdvancedSearchAction.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AdvancedSearchAction.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AdvancedSearchAction.java	Wed Jul 23 03:27:51 2008
@@ -71,6 +71,7 @@
             query.setTags(tags);
             query.setPropertyName(propertyName);
             query.setPropertyValue(propertyValue);
+            query.setContent(content);
 
             Resource qResults = query.execute(registry);
 

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- 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	Wed Jul 23 03:27:51 2008
@@ -47,6 +47,7 @@
     private String commentWords;
     private String propertyName;
     private String propertyValue;
+    private String content;
 
     private Set<String> tags;
     private String queryPath;
@@ -114,6 +115,7 @@
             if (propertyValue != null) {
                 params.add(propertyValue);
             }
+
         }
 
         Map paramMap = new HashMap();
@@ -121,6 +123,9 @@
             Object value = params.get(i);
             paramMap.put(Integer.toString(i + 1), value);
         }
+        if (content != null){
+            paramMap.put("content",content);
+        }
 
         return registry.executeQuery(queryPath, paramMap);
     }
@@ -207,6 +212,14 @@
         this.commentWords = commentWords;
     }
 
+    public String getContent(){
+        return this.content;
+    }
+
+    public void setContent(String content){
+        this.content = content;
+    }
+
     private boolean queryExists(String queryPath) throws RegistryException {
 
         UserRegistry systemRegistry =

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/advanced-search.jsp
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/webapps/src/main/webapp/admin/advanced-search.jsp?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/advanced-search.jsp	(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/advanced-search.jsp	Wed Jul 23 03:27:51 2008
@@ -174,6 +174,12 @@
                 <input type="text" name="propertyValue" value="" id="#_propertyValue"/>
             </td>
         </tr>
+        <tr>
+            <td>Including Content</td>
+            <td>
+                <input type="text" name="content" value="" id="#_content"/>
+            </td>
+        </tr>
     </table>
 </div>
 

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
URL: http://wso2.org/svn/browse/wso2/trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js?rev=19896&r1=19895&r2=19896&view=diff
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js	(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js	Wed Jul 23 03:27:51 2008
@@ -915,15 +915,16 @@
  	if($('#_updater').value!="") reason +=validateForInput($('#_updater'),"Updated by");
  	if($('#_tags').value!="") reason +=validateForInput($('#_tags'),"Tags");
  	if($('#_comments').value!="") reason +=validateForInput($('#_comments'),"Comments");
+    if($('#_content').value!="") reason +=validateForInput($('#_content'),"Including Content");
 
- 	reasonDiv.innerHTML=reason;
+     reasonDiv.innerHTML=reason;
  	if(reason!="") {
  		reasonDiv.style.display="block";
  		return false;
  	}
  	else {
          new Ajax.Updater('searchResuts', '/wso2registry/system/search/advanced',
-         { method: 'get', parameters: {createdAfter: $('#_cfromDate').value,createdBefore:$('#_ctoDate').value, updatedAfter: $('#_ufromDate').value,updatedBefore:$('#_utoDate').value,resourcePath:$('#_resourceName').value,author:$('#_author').value,updater:$('#_updater').value,tags:$('#_tags').value,commentWords:$('#_comments').value,propertyName:$('#_propertyName').value,propertyValue:$('#_propertyValue').value} });
+         { method: 'get', parameters: {createdAfter: $('#_cfromDate').value,createdBefore:$('#_ctoDate').value, updatedAfter: $('#_ufromDate').value,updatedBefore:$('#_utoDate').value,resourcePath:$('#_resourceName').value,author:$('#_author').value,updater:$('#_updater').value,tags:$('#_tags').value,commentWords:$('#_comments').value,propertyName:$('#_propertyName').value,propertyValue:$('#_propertyValue').value,content:$('#_content').value} });
          //document.forms["advancedSearch"].submit();
  	}
 }



More information about the Registry-dev mailing list