OSDN Git Service

ローカル添付ファイルもApache Luceneを使った全文検索の対象に追加。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / REnSearch.java
index 9dccbd6..46f2edf 100644 (file)
@@ -704,8 +704,10 @@ 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 ftlQuery = new NSqlQuery(conn.getConnection());\r
-               ftlQuery.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
+               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
@@ -735,11 +737,11 @@ public class REnSearch {
                                        }\r
                                }\r
                                \r
-                               // luceneによる全文検索\r
-                               ftlQuery.bindValue(":text", getWords().get(i));\r
-                               ftlQuery.exec();\r
-                               while(ftlQuery.next()) {\r
-                                       guid = ftlQuery.valueString(0);\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
@@ -748,6 +750,28 @@ public class REnSearch {
                                                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