OSDN Git Service

ローカル添付ファイルもApache Luceneを使った全文検索の対象に追加。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / REnSearch.java
index 7534d6b..46f2edf 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * This file is part of NixNote \r
+ * This file is part of NixNote/NeighborNote \r
  * Copyright 2009 Randy Baumgarte\r
  * \r
  * This file may be licensed under the terms of of the\r
@@ -33,7 +33,6 @@ import com.evernote.edam.type.Note;
 import com.evernote.edam.type.Notebook;\r
 import com.evernote.edam.type.Tag;\r
 \r
-import cx.fbn.nevernote.Global;\r
 import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 \r
@@ -392,16 +391,16 @@ public class REnSearch {
                                searchPhrases.add(word.toLowerCase());\r
                        }\r
                        if (!searchPhrase && pos < 0) {\r
-                               if (word != null && word.length() > 0 && !Global.automaticWildcardSearches())\r
+                               if (word != null && word.length() > 0/* && !Global.automaticWildcardSearches()*/)\r
                                        getWords().add(word); \r
-                               if (word != null && word.length() > 0 && Global.automaticWildcardSearches()) {\r
-                                       String wildcardWord = word;\r
-                                       if (!wildcardWord.startsWith("*"))\r
-                                               wildcardWord = "*"+wildcardWord;\r
-                                       if (!wildcardWord.endsWith("*"))\r
-                                               wildcardWord = wildcardWord+"*";\r
-                                       getWords().add(wildcardWord); \r
-                               }\r
+//                             if (word != null && word.length() > 0 && Global.automaticWildcardSearches()) {\r
+//                                     String wildcardWord = word;\r
+//                                     if (!wildcardWord.startsWith("*"))\r
+//                                             wildcardWord = "*"+wildcardWord;\r
+//                                     if (!wildcardWord.endsWith("*"))\r
+//                                             wildcardWord = wildcardWord+"*";\r
+//                                     getWords().add(wildcardWord); \r
+//                             }\r
 //                             getWords().add("*"+word+"*");           //// WILDCARD\r
                        }\r
                        if (word.startsWith("intitle:")) \r
@@ -705,12 +704,17 @@ public class REnSearch {
                NSqlQuery indexQuery = new NSqlQuery(conn.getIndexConnection());\r
                NSqlQuery mergeQuery = new NSqlQuery(conn.getConnection());\r
                NSqlQuery deleteQuery = new NSqlQuery(conn.getConnection());\r
+               NSqlQuery ftlNoteQuery = new NSqlQuery(conn.getConnection());\r
+               NSqlQuery ftlResourceQuery = new NSqlQuery(conn.getResourceConnection());\r
+               ftlNoteQuery.prepare("SELECT N.GUID AS GUID FROM FTL_SEARCH_DATA(:text, 0, 0) FT, NOTE N WHERE FT.TABLE='NOTE' AND N.GUID=FT.KEYS[0]");\r
+               ftlResourceQuery.prepare("SELECT R.GUID AS GUID FROM FTL_SEARCH_DATA(:text, 0, 0) FT, NOTERESOURCES R WHERE FT.TABLE='NOTERESOURCES' AND R.GUID=FT.KEYS[0]");\r
                \r
                insertQuery.prepare("Insert into SEARCH_RESULTS (guid) values (:guid)");\r
                mergeQuery.prepare("Insert into SEARCH_RESULTS_MERGE (guid) values (:guid)");\r
                \r
                if (subSelect) {\r
                        for (int i=0; i<getWords().size(); i++) {\r
+                               // wordsテーブルから検索\r
                                if (getWords().get(i).indexOf("*") == -1) {\r
                                        indexQuery.prepare("Select distinct guid from words where weight >= " +minimumRecognitionWeight +\r
                                                        " and word=:word");\r
@@ -732,6 +736,43 @@ public class REnSearch {
                                                mergeQuery.exec();\r
                                        }\r
                                }\r
+                               \r
+                               // luceneによる全文検索 ノートテーブル\r
+                               ftlNoteQuery.bindValue(":text", getWords().get(i));\r
+                               ftlNoteQuery.exec();\r
+                               while(ftlNoteQuery.next()) {\r
+                                       guid = ftlNoteQuery.valueString(0);\r
+                                       if (i==0 || any) {\r
+                                               insertQuery.bindValue(":guid", guid);\r
+                                               insertQuery.exec();\r
+                                       } else {\r
+                                               mergeQuery.bindValue(":guid", guid);\r
+                                               mergeQuery.exec();\r
+                                       }\r
+                               }\r
+                               // luceneによる全文検索 リソーステーブル\r
+                               NSqlQuery rQuery = new NSqlQuery(conn.getResourceConnection());\r
+                               ftlResourceQuery.bindValue(":text", getWords().get(i));\r
+                               ftlResourceQuery.exec();\r
+                               while(ftlResourceQuery.next()) {\r
+                                       guid = ftlResourceQuery.valueString(0);\r
+                                       \r
+                                       // リソースguidからノートguidを算出\r
+                                       rQuery.prepare("Select noteGuid from noteResources where guid=:guid");\r
+                                       rQuery.bindValue(":guid", guid);\r
+                                       rQuery.exec();\r
+                                       while(rQuery.next()) {\r
+                                               guid = rQuery.valueString(0);\r
+                                               if (i==0 || any) {\r
+                                                       insertQuery.bindValue(":guid", guid);\r
+                                                       insertQuery.exec();\r
+                                               } else {\r
+                                                       mergeQuery.bindValue(":guid", guid);\r
+                                                       mergeQuery.exec();\r
+                                               }\r
+                                       }\r
+                               }\r
+                               \r
                                if (i>0 && !any) {\r
                                        deleteQuery.exec("Delete from SEARCH_RESULTS where guid not in (select guid from SEARCH_RESULTS_MERGE)");\r
                                        deleteQuery.exec("Delete from SEARCH_RESULTS_MERGE");\r