OSDN Git Service

Merge branch 'japaneseSearch' into develop
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / Global.java
index 544d3cf..c69f16c 100644 (file)
@@ -53,6 +53,8 @@ import cx.fbn.nevernote.config.StartupConfig;
 import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;
 import cx.fbn.nevernote.gui.DateAttributeFilterTable;
 import cx.fbn.nevernote.gui.ShortcutKeys;
 import cx.fbn.nevernote.gui.ContainsAttributeFilterTable;
 import cx.fbn.nevernote.gui.DateAttributeFilterTable;
 import cx.fbn.nevernote.gui.ShortcutKeys;
+import cx.fbn.nevernote.sql.DatabaseConnection;
+import cx.fbn.nevernote.sql.driver.NSqlQuery;
 import cx.fbn.nevernote.utilities.ApplicationLogger;
 import cx.fbn.nevernote.utilities.Pair;
 
 import cx.fbn.nevernote.utilities.ApplicationLogger;
 import cx.fbn.nevernote.utilities.Pair;
 
@@ -139,7 +141,7 @@ public class Global {
     //public static int minimumWordCount = 2;
     
     // Regular expression to parse text with when indexing
     //public static int minimumWordCount = 2;
     
     // Regular expression to parse text with when indexing
-    private static String wordRegex;
+//    private static String wordRegex;
     
     // Experimental fixes.  Set via Edit/Preferences/Debugging
     public static boolean enableCarriageReturnFix = false;
     
     // Experimental fixes.  Set via Edit/Preferences/Debugging
     public static boolean enableCarriageReturnFix = false;
@@ -221,10 +223,10 @@ public class Global {
                getServer();  // Setup URL to connect to
                
                // Get regular expressions used to parse out words
                getServer();  // Setup URL to connect to
                
                // Get regular expressions used to parse out words
-               settings.beginGroup("General");
-               String regex = (String) settings.value("regex", "[,\\s]+");
-               setWordRegex(regex);
-               settings.endGroup();
+//             settings.beginGroup("General");
+//             String regex = (String) settings.value("regex", "[,\\s]+");
+//             setWordRegex(regex);
+//             settings.endGroup();
                
                //Setup debugging information
                settings.beginGroup("Debug");
                
                //Setup debugging information
                settings.beginGroup("Debug");
@@ -251,12 +253,12 @@ public class Global {
     }
 
     // Get/Set word parsing regular expression
     }
 
     // Get/Set word parsing regular expression
-    public static String getWordRegex() {
-       return wordRegex;
-    }
-    public static void setWordRegex(String r) {
-       wordRegex = r;
-    }
+//    public static String getWordRegex() {
+//     return wordRegex;
+//    }
+//    public static void setWordRegex(String r) {
+//     wordRegex = r;
+//    }
 
    // Set the debug message level
    public static void setMessageLevel(String msglevel) {
 
    // Set the debug message level
    public static void setMessageLevel(String msglevel) {
@@ -1880,18 +1882,18 @@ public class Global {
                settings.endGroup();    
     }
     // Get/Set characters that shouldn't be removed from a word
                settings.endGroup();    
     }
     // Get/Set characters that shouldn't be removed from a word
-    public static String getSpecialIndexCharacters() {
-               settings.beginGroup("Index");
-               String text = (String)settings.value("specialCharacters", "");
-               settings.endGroup();    
-               return text;
-    }
-    public static void setSpecialIndexCharacters(String value) {
-               settings.beginGroup("Index");
-               settings.setValue("specialCharacters", value);
-               settings.endGroup();    
-               databaseCache = value;
-    }
+//    public static String getSpecialIndexCharacters() {
+//             settings.beginGroup("Index");
+//             String text = (String)settings.value("specialCharacters", "");
+//             settings.endGroup();    
+//             return text;
+//    }
+//    public static void setSpecialIndexCharacters(String value) {
+//             settings.beginGroup("Index");
+//             settings.setValue("specialCharacters", value);
+//             settings.endGroup();    
+//             databaseCache = value;
+//    }
     
     //*****************************************************************************
     // Control how tag selection behaves (should they be "and" or "or" selections
     
     //*****************************************************************************
     // Control how tag selection behaves (should they be "and" or "or" selections
@@ -2018,27 +2020,27 @@ public class Global {
     }
     
     // If we should automatically wildcard searches
     }
     
     // If we should automatically wildcard searches
-    public static boolean automaticWildcardSearches() {
-               settings.beginGroup("General");
-               try {
-                       String value = (String)settings.value("automaticWildcard", "false");
-                       settings.endGroup();
-                       if (value.equals("true"))
-                               return true;
-                       else
-                               return false;
-               } catch (java.lang.ClassCastException e) {
-                       Boolean value = (Boolean) settings.value("automaticWildcard", false);
-                       settings.endGroup();
-                       return value;
-               }
-
-    }
-    public static void setAutomaticWildcardSearches(boolean value) {
-               settings.beginGroup("General");
-               settings.setValue("automaticWildcard", value);
-               settings.endGroup();    
-    }
+//    public static boolean automaticWildcardSearches() {
+//             settings.beginGroup("General");
+//             try {
+//                     String value = (String)settings.value("automaticWildcard", "false");
+//                     settings.endGroup();
+//                     if (value.equals("true"))
+//                             return true;
+//                     else
+//                             return false;
+//             } catch (java.lang.ClassCastException e) {
+//                     Boolean value = (Boolean) settings.value("automaticWildcard", false);
+//                     settings.endGroup();
+//                     return value;
+//             }
+//
+//    }
+//    public static void setAutomaticWildcardSearches(boolean value) {
+//             settings.beginGroup("General");
+//             settings.setValue("automaticWildcard", value);
+//             settings.endGroup();    
+//    }
 
     // If we should automatically select the children of any tag
     public static boolean displayRightToLeft() {
 
     // If we should automatically select the children of any tag
     public static boolean displayRightToLeft() {
@@ -2345,5 +2347,72 @@ public class Global {
                settings.endGroup();
                return value;
        }
                settings.endGroup();
                return value;
        }
+       
+       // タグを排除してプレーンテキストを抽出
+       public static String extractPlainText(String sourceText) {
+               String plainText = sourceText.replaceAll("<.+?>", "");  // タグを除去
+               plainText = plainText.replaceAll("\\s{2,}", " ");               // 2個以上の空白文字を1文字の空白に変換
+               String kaigyo = System.getProperty("line.separator");
+               plainText = plainText.replaceAll(kaigyo, "");                   // 改行を除去
+//             plainText = plainText.replaceAll("&lt;.+?&gt;", "");    // &lt;で始まり&gt;で終わる文字列を除去
+               
+               // HTML特殊文字のサニタイジングを解除
+               plainText = plainText.replaceAll("&#39;", "'");
+               plainText = plainText.replaceAll("&quot;", "\"");
+               plainText = plainText.replaceAll("&gt;", ">");
+               plainText = plainText.replaceAll("&lt;", "<");
+               plainText = plainText.replaceAll("&amp;", "&");
+               
+               plainText = plainText.replaceAll("&.+?;", "");                  // その他HTML特殊文字があれば除去
+               
+               return plainText;
+       }
+       
+       // 全文検索機能の対象となるテーブルとカラムを再構築
+       public static boolean rebuildFullTextNoteTarget(DatabaseConnection dbConn) {
+               NSqlQuery nQuery = new NSqlQuery(dbConn.getConnection());
+               StringBuilder noteTableTarget = new StringBuilder();
+               boolean success = true;
+               
+               if (Global.indexNoteBody()) {
+                       noteTableTarget.append("CONTENTTEXT");
+               }
+               if (Global.indexNoteTitle()) {
+                       if (noteTableTarget.length() > 0) {
+                               noteTableTarget.append(", ");
+                       }
+                       noteTableTarget.append("TITLE");
+               }
+               
+               if (noteTableTarget.length() > 0) {
+                       nQuery.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', :column);");
+                       nQuery.bindValue(":column", noteTableTarget.toString());
+                       if (!nQuery.exec()) {
+                               success = false;
+                       }
+               }
+               
+               return success;
+       }
+       
+       public static boolean rebuildFullTextResourceTarget(DatabaseConnection dbConn) {
+               NSqlQuery rQuery = new NSqlQuery(dbConn.getResourceConnection());
+               StringBuilder resourceTableTarget = new StringBuilder();
+               boolean success = true;
+               
+               if (Global.indexAttachmentsLocally()) {
+                       resourceTableTarget.append("RESOURCETEXT");
+               }
+               
+               if (resourceTableTarget.length() > 0) {
+                       rQuery.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTERESOURCES', :column);");
+                       rQuery.bindValue(":column", resourceTableTarget.toString());
+                       if (!rQuery.exec()) {
+                               success = false;
+                       }
+               }
+               
+               return success;
+       }
 }
 
 }