OSDN Git Service

連想ノートリストに表示するノートコンテンツをノートデータベースのContentTextから取得するように変更。全文検索対象の再構築をGlobalに移動。
authoryuki <kimaira7@gmail.com>
Tue, 9 Jul 2013 05:54:27 +0000 (14:54 +0900)
committeryuki <kimaira7@gmail.com>
Tue, 9 Jul 2013 05:54:27 +0000 (14:54 +0900)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/gui/RensoNoteListItem.java
src/cx/fbn/nevernote/sql/DatabaseConnection.java
src/cx/fbn/nevernote/sql/NoteTable.java
src/cx/fbn/nevernote/sql/REnSearch.java

index 8c18ab5..239520f 100644 (file)
@@ -53,6 +53,7 @@ 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.sql.driver.NSqlQuery;
 import cx.fbn.nevernote.utilities.ApplicationLogger;
 import cx.fbn.nevernote.utilities.Pair;
 
@@ -2342,5 +2343,33 @@ public class Global {
                
                return plainText;
        }
+       
+       // 全文検索機能の対象となるテーブルとカラムを再構築
+       public static boolean rebuildFullTextTarget(NSqlQuery query) {
+               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");
+               }
+               
+               // TODO 他の項目もあとで追加
+               
+               if (noteTableTarget.length() > 0) {
+                       query.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', :column);");
+                       query.bindValue(":column", noteTableTarget.toString());
+                       if (!query.exec()) {
+                               success = false;
+                       }
+               }
+               
+               return success;
+       }
 }
 
index 2b285c6..98ec261 100644 (file)
@@ -245,25 +245,7 @@ public class ConfigDialog extends QDialog {
                // 全文検索の対象項目を再設定\r
                NSqlQuery query = new NSqlQuery(conn.getConnection());\r
                query.exec("CALL FTL_DROP_ALL();");     // カラム単位で削除できないので一度全部消して、再構築\r
-               \r
-               StringBuilder noteTableTarget = new StringBuilder();\r
-               if (Global.indexNoteBody()) {\r
-                       noteTableTarget.append("CONTENTTEXT");\r
-               }\r
-               if (Global.indexNoteTitle()) {\r
-                       if (noteTableTarget.length() > 0) {\r
-                               noteTableTarget.append(", ");\r
-                       }\r
-                       noteTableTarget.append("TITLE");\r
-               }\r
-               \r
-               // TODO 他の項目もあとで追加\r
-               \r
-               if (noteTableTarget.length() > 0) {\r
-                       query.prepare("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', :column);");\r
-                       query.bindValue(":column", noteTableTarget.toString());\r
-                       query.exec();\r
-               }\r
+               Global.rebuildFullTextTarget(query);\r
                \r
                close();\r
        }\r
index e0842f6..732a0ef 100644 (file)
@@ -81,7 +81,8 @@ public class RensoNoteListItem extends QWidget{
                this.tagNames = new String(sb);
                
                // this.noteContent = new String(note.getContent());
-               this.noteContent = Global.extractPlainText(conn.getNoteTable().getNoteContentNoUTFConversion(note.getGuid()));
+//             this.noteContent = Global.extractPlainText(conn.getNoteTable().getNoteContentNoUTFConversion(note.getGuid()));
+               this.noteContent = conn.getNoteTable().getNoteContentText(note.getGuid());
                palette = new QPalette();
                palette.setColor(QPalette.ColorRole.Window, new QColor(255, 255, 255));
                this.setPalette(palette);
index deefdc8..1ea7e23 100644 (file)
@@ -311,12 +311,7 @@ public class DatabaseConnection {
                        // 全文検索のための準備
                        query.exec("CREATE ALIAS IF NOT EXISTS FTL_INIT FOR \"org.h2.fulltext.FullTextLucene.init\"");
                        query.exec("CALL FTL_INIT()");
-                       if (Global.indexNoteBody()) {
-                               query.exec("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', 'CONTENTTEXT');");
-                       }
-                       if (Global.indexNoteTitle()) {
-                               query.exec("CALL FTL_CREATE_INDEX('PUBLIC', 'NOTE', 'TITLE');");
-                       }
+                       Global.rebuildFullTextTarget(query);
                }
        }
        
index 181d222..36c0dca 100644 (file)
@@ -1770,7 +1770,35 @@ public class NoteTable {
         *
         * boolean retVal = query.valueBoolean(0, false); return retVal; }
         */
+       
+       // ノートコンテンツのプレーンテキストを取得
+       public String getNoteContentText(String noteGuid) {
+
+               if (noteGuid == null)
+                       return null;
+               if (noteGuid.trim().equals(""))
+                       return null;
 
+               NSqlQuery query = new NSqlQuery(db.getConnection());
+               query.prepare("Select contentText from Note where guid=:guid");
+               query.bindValue(":guid", noteGuid);
+               if (!query.exec()) {
+                       logger.log(logger.MEDIUM, "Noteテーブルからプレーンコンテンツの取得失敗");
+                       logger.log(logger.MEDIUM, query.lastError());
+                       return null;
+               }
+               if (!query.next()) {
+                       logger.log(logger.EXTREME, "SQL Retrieve failed for note guid "
+                                       + noteGuid + " in getNotePlainContent()");
+                       logger.log(logger.EXTREME, " -> " + query.lastError().toString());
+                       logger.log(logger.EXTREME, " -> " + query.lastError());
+                       return null;
+               }
+
+               String noteContentText = query.valueString(0);
+
+               return noteContentText;
+       }
 }      
 
 
index 4ee21b7..bafb04b 100644 (file)
@@ -380,7 +380,6 @@ public class REnSearch {
        private void parseTerms(List<String> words) {\r
                for (int i=0; i<words.size(); i++) {\r
                        String word = words.get(i);\r
-                       System.out.println("word = " + word);\r
                        int pos = word.indexOf(":");\r
                        if (word.startsWith("any:")) {\r
                                any = true;\r