[jboss-cvs] JBossBlog SVN: r292 - in trunk: view/layout and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 24 09:34:27 EDT 2008


Author: adamw
Date: 2008-04-24 09:34:27 -0400 (Thu, 24 Apr 2008)
New Revision: 292

Modified:
   trunk/src/action/org/jboss/blog/session/search/PostSearchBean.java
   trunk/view/layout/menu.xhtml
   trunk/view/manage/index.xhtml
Log:


Modified: trunk/src/action/org/jboss/blog/session/search/PostSearchBean.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/search/PostSearchBean.java	2008-04-24 12:17:15 UTC (rev 291)
+++ trunk/src/action/org/jboss/blog/session/search/PostSearchBean.java	2008-04-24 13:34:27 UTC (rev 292)
@@ -39,6 +39,12 @@
 
     private int resultsCount;
 
+    private static char[] LUCENE_SPECIAL =
+            { '\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '\"', '~', ':' };
+
+    private static String[] ESCAPED_LUCENE_SPECIAL =
+            { "\\\\", "\\+", "\\-", "\\&", "\\|", "\\!", "\\(", "\\)", "\\{", "\\}", "\\[", "\\]", "\\^", "\\\"", "\\~", "\\:" };
+
     public String getQuery() {
         return query;
     }
@@ -83,11 +89,36 @@
         return results;
     }
 
+    private String replaceAll(String where, char what, String replacement) {
+        StringBuilder sb = new StringBuilder();
+
+        for (int i=0; i<where.length(); i++) {
+            char whereAtI = where.charAt(i);
+            if (whereAtI == what) {
+                sb.append(replacement);
+            } else {
+                sb.append(whereAtI);
+            }
+        }
+
+        return sb.toString();
+    }
+
+    private String escapeQuery(String query) {
+        for (int i=0; i<LUCENE_SPECIAL.length; i++) {
+            query = replaceAll(query, LUCENE_SPECIAL[i], ESCAPED_LUCENE_SPECIAL[i]);
+        }
+
+        System.out.println("query = " + query);
+
+        return query;
+    }
+
     private FullTextQuery getFullTextQuery() throws ParseException {
         MultiFieldQueryParser parser = new MultiFieldQueryParser(
                 new String[]{ "title", "content", "author" },
                 new StandardAnalyzer());
-        Query luceneQuery = parser.parse(getQuery());
+        Query luceneQuery = parser.parse(escapeQuery(getQuery()));
 
         FullTextQuery fullTextQuery = entityManager.createFullTextQuery(luceneQuery, Post.class);
         fullTextQuery.setProjection(FullTextQuery.SCORE, FullTextQuery.THIS);

Modified: trunk/view/layout/menu.xhtml
===================================================================
--- trunk/view/layout/menu.xhtml	2008-04-24 12:17:15 UTC (rev 291)
+++ trunk/view/layout/menu.xhtml	2008-04-24 13:34:27 UTC (rev 292)
@@ -26,18 +26,16 @@
                 </li>
                 <li><a href="https://www.redhat.com/apps/store/jboss/">Subscribe</a>&#160;&#160;|&#160;&#160;</li>
                 <li><a href="http://www.jboss.com/index.html?op=checkage&amp;module=user">Register</a>&#160;&#160;|&#160;&#160;</li>
-                <s:fragment rendered="false">
-                    <li>
-                        Search:
-                        <h:inputText style="border: 1px solid #6e6e6e; font: 10px Verdana, Helvetica, Arial, sans-serif; padding-left: 2px; margin-left: 10px;"
-                                     value="#{postSearch.query}" />
-                        <h:commandButton value="Search" action="/search/search.xhtml"
-                                         image="http://labs.jboss.com/file-access/default/theme/images/common/ico_searcharrow.gif"
-                                         style="width:13px; height:13px">
-                            <s:conversationPropagation value="none" />
-                        </h:commandButton>
-                    </li>
-                </s:fragment>
+                <li>
+                    Search:
+                    <h:inputText style="border: 1px solid #6e6e6e; font: 10px Verdana, Helvetica, Arial, sans-serif; padding-left: 2px; margin-left: 10px;"
+                                 value="#{postSearch.query}" />
+                    <h:commandButton value="Search" action="/search/search.xhtml"
+                                     image="http://labs.jboss.com/file-access/default/theme/images/common/ico_searcharrow.gif"
+                                     style="width:13px; height:13px">
+                        <s:conversationPropagation value="none" />
+                    </h:commandButton>
+                </li>
             </ul>
         </h:form>
     </div>

Modified: trunk/view/manage/index.xhtml
===================================================================
--- trunk/view/manage/index.xhtml	2008-04-24 12:17:15 UTC (rev 291)
+++ trunk/view/manage/index.xhtml	2008-04-24 13:34:27 UTC (rev 292)
@@ -68,9 +68,7 @@
             <dt>Global posts operations:</dt>
             <hr />
             <dd><s:link value="Fix html in all posts" action="#{feedView.fixHtml}" /></dd>
-            <s:fragment rendered="false">
-                <dd><s:link value="Re-index posts (for search)" action="#{postSearch.reindex}" /></dd>
-            </s:fragment>
+            <dd><s:link value="Re-index posts (for search)" action="#{postSearch.reindex}" /></dd>
         </s:fragment>
         <dt>Existing feed operations:</dt>
         <hr />




More information about the jboss-cvs-commits mailing list