roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gango...@apache.org
Subject svn commit: r357101 - in /incubator/roller/trunk: src/org/roller/business/search/operations/IndexOperation.java src/org/roller/config/RollerConfig.java web/WEB-INF/classes/roller.properties
Date Fri, 16 Dec 2005 01:37:37 GMT
Author: gangolli
Date: Thu Dec 15 17:37:34 2005
New Revision: 357101

URL: http://svn.apache.org/viewcvs?rev=357101&view=rev
Log:
Added functionality for disabling indexing of comments, based loosely on patch suggested by
Matt Schmidt.

Modified:
    incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java
    incubator/roller/trunk/src/org/roller/config/RollerConfig.java
    incubator/roller/trunk/web/WEB-INF/classes/roller.properties

Modified: incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java?rev=357101&r1=357100&r2=357101&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java (original)
+++ incubator/roller/trunk/src/org/roller/business/search/operations/IndexOperation.java Thu
Dec 15 17:37:34 2005
@@ -20,6 +20,7 @@
 import org.roller.pojos.WeblogCategoryData;
 import org.roller.pojos.WeblogEntryData;
 import org.roller.util.Utilities;
+import org.roller.config.RollerConfig;
 
 /**
  * @author aim4min
@@ -51,28 +52,41 @@
     // ================================================================
 
     protected Document getDocument(WeblogEntryData data) {
-        StringBuffer commentEmail = new StringBuffer();
-        StringBuffer commentContent = new StringBuffer();
-        StringBuffer commentName = new StringBuffer();
-
-        List comments = data.getComments();
-        if (comments != null) {
-            for (Iterator cItr = comments.iterator(); cItr.hasNext();) {
-                CommentData comment = (CommentData) cItr.next();
-                if (comment.getSpam() == null || !comment.getSpam().booleanValue()) {
-                    if (comment.getContent() != null) {
-                        commentContent.append(comment.getContent());
-                        commentContent.append(",");
-                    }
-                    if (comment.getEmail() != null) {
-                        commentEmail.append(comment.getEmail());
-                        commentEmail.append(",");
-                    }
-                    if (comment.getName() != null) {
-                        commentName.append(comment.getName());
-                        commentName.append(",");
+
+        // Actual comment content is indexed only if search.index.comments
+        // is true or absent from the (static) configuration properties.
+        // If false in the configuration, comments are treated as if empty.
+        boolean indexComments = RollerConfig.getBooleanProperty("search.index.comments",
true);
+
+        String commentContent = "";
+        String commentEmail = "";
+        String commentName = "";
+        if (indexComments) {
+            List comments = data.getComments();
+            if (comments != null) {
+                StringBuffer commentEmailBuf = new StringBuffer();
+                StringBuffer commentContentBuf = new StringBuffer();
+                StringBuffer commentNameBuf = new StringBuffer();
+                for (Iterator cItr = comments.iterator(); cItr.hasNext();) {
+                    CommentData comment = (CommentData) cItr.next();
+                    if (comment.getSpam() == null || !comment.getSpam().booleanValue()) {
+                        if (comment.getContent() != null) {
+                            commentContentBuf.append(comment.getContent());
+                            commentContentBuf.append(",");
+                        }
+                        if (comment.getEmail() != null) {
+                            commentEmailBuf.append(comment.getEmail());
+                            commentEmailBuf.append(",");
+                        }
+                        if (comment.getName() != null) {
+                            commentNameBuf.append(comment.getName());
+                            commentNameBuf.append(",");
+                        }
                     }
                 }
+                commentEmail = commentEmailBuf.toString();
+                commentContent = commentContentBuf.toString();
+                commentName = commentNameBuf.toString();
             }
         }
 
@@ -99,12 +113,9 @@
                 .toString()));
 
         // index Comments
-        doc.add(Field.UnStored(FieldConstants.C_CONTENT, commentContent
-                .toString()));
-        doc
-                .add(Field.UnStored(FieldConstants.C_EMAIL, commentEmail
-                        .toString()));
-        doc.add(Field.UnStored(FieldConstants.C_NAME, commentName.toString()));
+        doc.add(Field.UnStored(FieldConstants.C_CONTENT, commentContent));
+        doc.add(Field.UnStored(FieldConstants.C_EMAIL, commentEmail));
+        doc.add(Field.UnStored(FieldConstants.C_NAME, commentName));
 
         doc.add(Field.UnStored(FieldConstants.CONSTANT, FieldConstants.CONSTANT_V));
 

Modified: incubator/roller/trunk/src/org/roller/config/RollerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/RollerConfig.java?rev=357101&r1=357100&r2=357101&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/RollerConfig.java (original)
+++ incubator/roller/trunk/src/org/roller/config/RollerConfig.java Thu Dec 15 17:37:34 2005
@@ -5,18 +5,15 @@
 
 package org.roller.config;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.util.PropertyExpander;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
 import java.util.Enumeration;
 import java.util.Properties;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.roller.util.PropertyExpander;
 
 
 /**
@@ -139,19 +136,24 @@
 
 
     /**
-     * Retrieve a property as a boolean ... defaults to false if there is an error
+     * Retrieve a property as a boolean ... defaults to false if not present.
      **/
     public static boolean getBooleanProperty(String name) {
+        return getBooleanProperty(name,false);
+    }
 
+    /**
+     * Retrieve a property as a boolean ... with specified default if not present.
+     */
+    public static boolean getBooleanProperty(String name, boolean defaultValue) {
         // get the value first, then convert
         String value = RollerConfig.getProperty(name);
 
         if(value == null)
-            return false;
+            return defaultValue;
 
         return (new Boolean(value)).booleanValue();
     }
-
 
     /**
      * Retrieve all property keys

Modified: incubator/roller/trunk/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/WEB-INF/classes/roller.properties?rev=357101&r1=357100&r2=357101&view=diff
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/roller.properties Thu Dec 15 17:37:34 2005
@@ -54,6 +54,9 @@
 # Directory in which search index is to be created (delete this directory to
 # force Roller to recreate the entire search index)
 search.index.dir=${user.home}/roller_data/search-index
+# Whether or not to include comments in the search index.  If this
+# is false, comments are not included in the index.
+search.index.comments=true
 
 #----------------------------------
 # Cache settings.



Mime
View raw message