OSDN Git Service

Merge branch 'japaneseSearch' into develop
authoryuki <kimaira7@gmail.com>
Mon, 2 Sep 2013 08:29:20 +0000 (17:29 +0900)
committeryuki <kimaira7@gmail.com>
Mon, 2 Sep 2013 08:29:20 +0000 (17:29 +0900)
Conflicts:
.classpath
src/cx/fbn/nevernote/dialog/ConfigDialog.java

1  2 
.classpath
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java

diff --combined .classpath
@@@ -2,8 -2,7 +2,7 @@@
  <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 -      <classpathentry kind="lib" path="lib/evernote-api-1.20.jar"/>
 +      <classpathentry kind="lib" path="lib/evernote-api-1.25.0.jar"/>
-       <classpathentry kind="lib" path="lib/h2-1.3.158.jar"/>
        <classpathentry kind="lib" path="lib/libthrift.jar"/>
        <classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>
        <classpathentry kind="lib" path="lib/commons-lang3-3.0.jar"/>
        <classpathentry kind="lib" path="lib/httpcore-4.1.jar"/>
        <classpathentry kind="lib" path="lib/httpmime-4.1.1.jar"/>
        <classpathentry kind="lib" path="lib/pdfbox-app-1.6.0.jar"/>
-       <classpathentry kind="lib" path="C:/pleiades/scribe-1.3.0.jar"/>
-       <classpathentry kind="lib" path="C:/pleiades/qtjambi-win32-lgpl-4.5.2_01/qtjambi-4.5.2_01.jar"/>
-       <classpathentry kind="lib" path="C:/pleiades/qtjambi-win32-lgpl-4.5.2_01/qtjambi-win32-msvc2005-4.5.2_01.jar"/>
+       <classpathentry kind="lib" path="lib/scribe-1.3.0.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Yuki/Desktop/pleiades/qtjambi-win64-4.5.2_01.jar"/>
+       <classpathentry kind="lib" path="C:/Users/Yuki/Desktop/pleiades/qtjambi-win64-msvc2005x64-4.5.2_01.jar"/>
+       <classpathentry kind="lib" path="lib/lucene-core-3.6.2.jar"/>
+       <classpathentry kind="lib" path="lib/h2-1.3.163.jar"/>
+       <classpathentry kind="lib" path="lib/h2-lucene-ex-1.3.163.jar"/>
+       <classpathentry kind="lib" path="lib/lucene-analyzers-3.6.2.jar"/>
        <classpathentry kind="output" path="bin"/>
  </classpath>
@@@ -53,6 -53,8 +53,8 @@@ import cx.fbn.nevernote.config.StartupC
  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;
  
@@@ -67,8 -69,8 +69,8 @@@
  public class Global {
        // Set current version and the known versions.
        // ICHANGED 自分用に変更
 -      public static String version = "0.1.3";
 -      public static String[] validVersions = {"0.1.3", "0.1.2", "0.1.1", "0.1"};
 +      public static String version = "0.2";
 +      public static String[] validVersions = {"0.2", "0.1.3", "0.1.2", "0.1.1", "0.1"};
        
      public static String username = ""; 
      //public static String password = "";     
      //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;
                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");
      }
  
      // 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) {
                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
      }
      
      // 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() {
                settings.endGroup();
                return value;
        }
 +      
 +      // Evernote関連ノート機能統合に対する重み付け
 +      public static void setENRelatedNotesWeight(int weight) {
 +              settings.beginGroup("RensoNoteList");
 +              settings.setValue("enRelatedNotesWeight", weight);
 +              settings.endGroup();
 +      }
 +      public static int getENRelatedNotesWeight() {
 +              settings.beginGroup("RensoNoteList");
 +              Integer value;
 +              try {
 +                      String val = (String)settings.value("enRelatedNotesWeight", 10);
 +                      value = new Integer(val.trim());
 +              } catch (Exception e) {
 +                      try {
 +                              value = (Integer)settings.value("enRelatedNotesWeight", 10);
 +                      } catch (Exception e1) {
 +                              value = 10;
 +                      }
 +              }
 +              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;
+       }
  }
  
@@@ -47,6 -47,7 +47,6 @@@ import java.util.Vector
  
  import org.apache.log4j.Level;
  import org.apache.log4j.Logger;
 -import org.apache.thrift.TException;
  import org.h2.tools.ChangeFileEncryption;
  
  import com.evernote.edam.error.EDAMNotFoundException;
@@@ -65,7 -66,6 +65,7 @@@ import com.evernote.edam.type.Resource
  import com.evernote.edam.type.SavedSearch;
  import com.evernote.edam.type.Tag;
  import com.evernote.edam.type.User;
 +import com.evernote.thrift.TException;
  import com.trolltech.qt.QThread;
  import com.trolltech.qt.core.QByteArray;
  import com.trolltech.qt.core.QDateTime;
@@@ -208,7 -208,6 +208,7 @@@ import cx.fbn.nevernote.xml.ExportData
  import cx.fbn.nevernote.xml.ImportData;
  import cx.fbn.nevernote.xml.ImportEnex;
  import cx.fbn.nevernote.xml.NoteFormatter;
 +//import org.apache.thrift.TException;
  
  
  public class NeverNote extends QMainWindow{
      int                                       tagDeadCount=0;                         // number of consecutive dead times for the tag thread
      int                                       trashDeadCount=0;                       // number of consecutive dead times for the trash thread
      int                               saveThreadDeadCount=0;          // number of consecutive dead times for the save thread
 +    int                               enRelatedNotesThreadDeadCount=0;        // number of consecutive dead times for the EvernoteRelatedNotes Thread
      boolean                           disableTagThreadCheck=false;
      boolean                           disableNotebookThreadCheck=false;
      boolean                           disableTrashThreadCheck=false;
      boolean                           disableSaveThreadCheck=false;
      boolean                           disableSyncThreadCheck=false;
      boolean                           disableIndexThreadCheck=false;
 +    boolean                           disableENRelatedNotesThreadCheck=false;
      
      HashMap<String, String>           noteCache;                      // Cash of note content 
      HashMap<String, Boolean>  readOnlyCache;          // List of cashe notes that are read-only
                indexThread = new QThread(indexRunner, "Index Thread");
          indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
          indexRunner.indexImageRecognition = Global.indexImageRecognition();
-         indexRunner.indexNoteBody = Global.indexNoteBody();
-         indexRunner.indexNoteTitle = Global.indexNoteTitle();
-         indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
//        indexRunner.indexNoteBody = Global.indexNoteBody();
//        indexRunner.indexNoteTitle = Global.indexNoteTitle();
//        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
                indexThread.start();
                
          synchronizeAnimationTimer = new QTimer();
          
                // ICHANGED
                // 連想ノートリストをセットアップ
 -              rensoNoteList = new RensoNoteList(conn, this);
 +              rensoNoteList = new RensoNoteList(conn, this, syncRunner);
                rensoNoteList.itemPressed.connect(this,
                                "rensoNoteItemPressed(QListWidgetItem)");
                rensoNoteListDock = new QDockWidget(tr("Renso Note List"), this);
                saveNote();
                listManager.stop();
                saveWindowState();
 +              
 +              // 連想ノートリストのEvernote関連ノート取得スレッドを終了
 +              rensoNoteList.stopThread();
  
                if (tempFiles != null)
                        tempFiles.clear();
                saveNoteColumnPositions();
                saveNoteIndexWidth();
                showColumns();
-         ConfigDialog settings = new ConfigDialog(this);
+         ConfigDialog settings = new ConfigDialog(this, conn);
          String dateFormat = Global.getDateFormat();
          String timeFormat = Global.getTimeFormat();
          
          
          settings.exec();
          indexRunner.indexAttachmentsLocally = Global.indexAttachmentsLocally();
-         indexRunner.indexNoteBody = Global.indexNoteBody();
-         indexRunner.indexNoteTitle = Global.indexNoteTitle();
-         indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
//        indexRunner.indexNoteBody = Global.indexNoteBody();
//        indexRunner.indexNoteTitle = Global.indexNoteTitle();
//        indexRunner.specialIndexCharacters = Global.getSpecialIndexCharacters();
          indexRunner.indexImageRecognition = Global.indexImageRecognition();
          if (Global.showTrayIcon() || Global.minimizeOnClose())
                trayIcon.show();
                } else
                        indexThreadDeadCount=0;
  
 -              
 +              if (!rensoNoteList.getEnRelatedNotesThread().isAlive()) {
 +                      enRelatedNotesThreadDeadCount++;
 +                      if (enRelatedNotesThreadDeadCount > MAX && !disableENRelatedNotesThreadCheck) {
 +                              QMessageBox.information(this, tr("A thread has died."), tr("It appears as the Evernote Related Notes thread has died.  I recommend "+
 +                                      "checking stopping NeighborNote, saving the logs for later viewing, and restarting.  Sorry."));
 +                              disableENRelatedNotesThreadCheck = true;
 +                      }
 +              } else
 +                      enRelatedNotesThreadDeadCount=0;
        }
  
        private void thumbnailTimer() {
                fromHistory.put(from,  fromHistory.get(to));
                fromHistory.put(to, fromHist);
        }
 +      
 +      // 連想ノートリストのgetter
 +      public RensoNoteList getRensoNoteList() {
 +              return rensoNoteList;
 +      }
  }
@@@ -41,9 -41,11 +41,11 @@@ import com.trolltech.qt.gui.QListWidget
  import com.trolltech.qt.gui.QPushButton;\r
  import com.trolltech.qt.gui.QStackedWidget;\r
  import com.trolltech.qt.gui.QVBoxLayout;\r
 -import com.trolltech.qt.gui.QWidget;\r
  \r
  import cx.fbn.nevernote.Global;\r
 +import cx.fbn.nevernote.NeverNote;\r
+ import cx.fbn.nevernote.sql.DatabaseConnection;\r
+ import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
  public class ConfigDialog extends QDialog {\r
        private final QListWidget                               contentsWidget;\r
        private final ConfigFontPage                    fontPage;\r
        private final ConfigAppearancePage              appearancePage;\r
        private final ConfigSpellPage                   spellPage;\r
        private final ConfigIndexPage                   indexPage;\r
 -      // ICHANGED\r
 -      private final ConfigRensoNoteListPage           rensoNoteListPage;\r
 +      private final ConfigRensoNoteListPage   rensoNoteListPage;\r
 +      private final NeverNote                                 parent;\r
+       private final DatabaseConnection conn;\r
        \r
--    private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
--      \r
-       public ConfigDialog(NeverNote parent) {\r
 -      public ConfigDialog(QWidget parent, DatabaseConnection conn) {\r
++      private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
++    \r
++      public ConfigDialog(NeverNote parent, DatabaseConnection conn) {\r
 +              this.parent = parent;\r
+               this.conn = conn;\r
                \r
                contentsWidget = new QListWidget(this);\r
                setWindowIcon(new QIcon(iconPath+"config.png"));\r
                Global.setIndexNoteBody(indexPage.getIndexNoteBody());\r
                Global.setIndexNoteTitle(indexPage.getIndexNoteTitle());\r
                Global.setIndexImageRecognition(indexPage.getIndexImageRecognition());\r
              Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());\r
              Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
//            Global.setAutomaticWildcardSearches(indexPage.getAutomaticWildcardSearches());\r
//            Global.setSpecialIndexCharacters(indexPage.getSpecialCharacters());\r
                Global.setIncludeTagChildren(appearancePage.getIncludeTagChildren());\r
                Global.setDisplayRightToLeft(appearancePage.getDisplayRightToLeft());\r
                \r
                Global.userStoreUrl = "https://"+debugPage.getServer()+"/edam/user";\r
              Global.setWordRegex(indexPage.getRegex());\r
//            Global.setWordRegex(indexPage.getRegex());\r
                Global.setRecognitionWeight(indexPage.getRecognitionWeight());\r
                Global.setIndexThreadSleepInterval(indexPage.getSleepInterval());\r
                Global.setMessageLevel( debugPage.getDebugLevel());\r
                Global.setBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
                Global.setCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
                Global.setAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
--              Global.setRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());
--              Global.setSameTagWeight(rensoNoteListPage.getSameTagWeight());
++              Global.setRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());\r
++              Global.setSameTagWeight(rensoNoteListPage.getSameTagWeight());\r
                Global.setSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
 +              Global.setENRelatedNotesWeight(rensoNoteListPage.getENRelatedNotesWeight());\r
                \r
                // ICHANGED\r
                Global.setMergeRensoNote(rensoNoteListPage.getMergeChecked());\r
                Global.setVerifyExclude(rensoNoteListPage.getVerifyExcludeChecked());\r
                Global.setRensoListItemMaximum(rensoNoteListPage.getRensoListItemMaximum());\r
                \r
 +              // 連想ノートリストをリフレッシュ\r
 +              parent.getRensoNoteList().refreshRensoNoteList(parent.getCurrentNoteGuid());\r
 +              \r
+               // 全文検索の対象項目を再設定\r
+               NSqlQuery nQuery = new NSqlQuery(conn.getConnection());\r
+               NSqlQuery rQuery = new NSqlQuery(conn.getResourceConnection()); \r
+               // カラム単位で削除できないので一度全部消す\r
+               nQuery.exec("CALL FTL_DROP_ALL();");\r
+               rQuery.exec("CALL FTL_DROP_ALL();");\r
+               // 再構築\r
+               Global.rebuildFullTextNoteTarget(conn);\r
+               Global.rebuildFullTextResourceTarget(conn);\r
+               \r
                close();\r
        }\r
        \r
        // Create icons used for navigating the page\r
        public void createIcons() {\r
                String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
 -\r
                \r
                QListWidgetItem formatsButton = new QListWidgetItem(contentsWidget);\r
                formatsButton.setText(tr("Appearance"));\r
                appearancePage.setDisplayRightToLeft(Global.displayRightToLeft());\r
                appearancePage.setStartupNotebook(Global.getStartupNotebook());\r
                \r
              indexPage.setRegex(Global.getWordRegex());\r
//            indexPage.setRegex(Global.getWordRegex());\r
                indexPage.setSleepInterval(Global.getIndexThreadSleepInterval());\r
                connectionPage.setSyncInterval(Global.getSyncInterval());\r
                \r