OSDN Git Service

Added "stack:" to supported search terms.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / REnSearch.java
index c6502b7..7668f25 100644 (file)
@@ -55,19 +55,18 @@ public class REnSearch {
        private final List<String>      sourceApplication;\r
        private final List<String>      recoType;\r
        private final List<String>      todo;\r
+       private final List<String>  stack;\r
        private final List<Tag>         tagIndex;\r
        private final ApplicationLogger logger;\r
 //     private final DatabaseConnection db;\r
        private boolean any;\r
-       private int     minimumWordLength = 3;\r
        private int minimumRecognitionWeight = 80;\r
        private final DatabaseConnection conn;\r
        \r
-       public REnSearch(DatabaseConnection c, ApplicationLogger l, String s, List<Tag> t, int m, int r) {\r
+       public REnSearch(DatabaseConnection c, ApplicationLogger l, String s, List<Tag> t, int r) {\r
                logger = l;\r
                conn = c;\r
                tagIndex = t;\r
-               minimumWordLength = m;\r
                minimumRecognitionWeight = r;\r
                searchWords = new ArrayList<String>();\r
                searchPhrases = new ArrayList<String>();\r
@@ -87,6 +86,7 @@ public class REnSearch {
                recoType = new ArrayList<String>();\r
                todo = new ArrayList<String>();\r
                any = false;\r
+               stack = new ArrayList<String>();\r
                \r
                if (s == null) \r
                        return;\r
@@ -112,7 +112,7 @@ public class REnSearch {
        public List<String> getCreated() { return created; }\r
        public List<String> getUpdated() { return updated; }\r
        public List<String> getSubjectDate() { return subjectDate; }\r
-       \r
+       public List<String> getStack() { return stack; }\r
 \r
        // match tag names\r
        private boolean matchTagsAll(List<String> tagNames) {\r
@@ -198,6 +198,28 @@ public class REnSearch {
                        return matchListAll(getNotebooks(), name);\r
        }\r
        // Match notebooks in search terms against notes\r
+       private boolean matchNotebookStack(String guid) {\r
+               if (getStack().size() == 0)\r
+                       return true;\r
+               NotebookTable bookTable = new NotebookTable(logger, conn);\r
+               List<Notebook> books = bookTable.getAll();\r
+\r
+               String name = new String("");\r
+               for (int i=0; i<books.size(); i++) {\r
+                       if (guid.equalsIgnoreCase(books.get(i).getGuid())) {\r
+                               name = books.get(i).getStack();\r
+                               i=books.size();\r
+                       }\r
+               }\r
+               if (name == null)\r
+                       name = "";\r
+               if (any)\r
+                       return matchListAny(getStack(), name);\r
+               else\r
+                       return matchListAll(getStack(), name);\r
+       }\r
+\r
+       // Match notebooks in search terms against notes\r
        private boolean matchListAny(List<String> list, String title) {\r
                if (list.size() == 0)\r
                        return true;\r
@@ -360,7 +382,6 @@ public class REnSearch {
        // subject date\r
 \r
        private void parseTerms(List<String> words) {\r
-               int minLen = minimumWordLength;\r
                \r
                for (int i=0; i<words.size(); i++) {\r
                        String word = words.get(i);\r
@@ -375,8 +396,9 @@ public class REnSearch {
                                searchPhrase=true;\r
                                searchPhrases.add(word.toLowerCase());\r
                        }\r
-                       if (!searchPhrase && pos < 0 && (word.length() >= minLen || word.indexOf('*')>=0)) \r
-                               getWords().add(word);\r
+                       if (!searchPhrase && pos < 0) \r
+                               getWords().add(word); \r
+//                             getWords().add("*"+word+"*");           //// WILDCARD\r
                        if (word.startsWith("intitle:")) \r
                                intitle.add("*"+word+"*");\r
                        if (word.startsWith("-intitle:")) \r
@@ -413,6 +435,10 @@ public class REnSearch {
                                todo.add(word);\r
                        if (word.startsWith("-todo:")) \r
                                todo.add(word);\r
+                       if (word.startsWith("stack:"))\r
+                               stack.add(word);\r
+                       if (word.startsWith("-stack:"))\r
+                               stack.add(word);\r
 \r
                        if (word.startsWith("latitude:")) \r
                                latitude.add(word);\r
@@ -733,6 +759,8 @@ public class REnSearch {
                                        good = false;\r
                                if (good && !matchNotebook(n.getNotebookGuid()))\r
                                        good = false;\r
+                               if (good && !matchNotebookStack(n.getNotebookGuid()))\r
+                                       good = false;\r
                                if (good && !matchListAny(getIntitle(), n.getTitle()))\r
                                        good = false;\r
                                if (good && !matchListAny(getAuthor(), n.getAttributes().getAuthor()))\r
@@ -754,6 +782,8 @@ public class REnSearch {
                                        good = false;\r
                                if (good && !matchNotebook(n.getNotebookGuid()))\r
                                        good = false;\r
+                               if (good && !matchNotebookStack(n.getNotebookGuid()))\r
+                                       good = false;\r
                                if (good && !matchListAll(getIntitle(), n.getTitle()))\r
                                        good = false;\r
                                if (good && !matchListAll(getAuthor(), n.getAttributes().getAuthor()))\r