OSDN Git Service
(root)
/
neighbornote
/
NeighborNote.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
63fcb6f
)
Reworked search logic to better handle multiple positive/negative matching of the...
author
Randy Baumgarte
<randy@fbn.cx>
Mon, 23 Jan 2012 12:47:51 +0000
(07:47 -0500)
committer
Randy Baumgarte
<randy@fbn.cx>
Mon, 23 Jan 2012 12:47:51 +0000
(07:47 -0500)
src/cx/fbn/nevernote/sql/REnSearch.java
patch
|
blob
|
history
diff --git
a/src/cx/fbn/nevernote/sql/REnSearch.java
b/src/cx/fbn/nevernote/sql/REnSearch.java
index
c6802e6
..
cec989a
100644
(file)
--- a/
src/cx/fbn/nevernote/sql/REnSearch.java
+++ b/
src/cx/fbn/nevernote/sql/REnSearch.java
@@
-129,19
+129,14
@@
public class REnSearch {
\r
if (tagNames.size() == 0 && !negative)
\r
return false;
\r
\r
if (tagNames.size() == 0 && !negative)
\r
return false;
\r
- if (tagNames.size() == 0 && negative)
\r
- return true;
\r
\r
\r
- boolean good = false;
\r
- for (int i=0; i<tagNames.size() && !good; i++) {
\r
+ for (int i=0; i<tagNames.size(); i++) {
\r
boolean matches = Pattern.matches(filterName.toLowerCase(),tagNames.get(i).toLowerCase());
\r
boolean matches = Pattern.matches(filterName.toLowerCase(),tagNames.get(i).toLowerCase());
\r
- if (matches && !negative)
\r
-
good = tru
e;
\r
- if (
!
matches && negative)
\r
-
good = tru
e;
\r
+ if (
!
matches && !negative)
\r
+
return fals
e;
\r
+ if (matches && negative)
\r
+
return fals
e;
\r
}
\r
}
\r
- if (!good)
\r
- return false;
\r
}
\r
return true;
\r
}
\r
}
\r
return true;
\r
}
\r
@@
-152,8
+147,7
@@
public class REnSearch {
return true;
\r
\r
boolean negative = false;
\r
return true;
\r
\r
boolean negative = false;
\r
- boolean found = false;
\r
-
\r
+
\r
for (int j=0; j<list.size(); j++) {
\r
negative = false;
\r
if (list.get(j).startsWith("-"))
\r
for (int j=0; j<list.size(); j++) {
\r
negative = false;
\r
if (list.get(j).startsWith("-"))
\r
@@
-162,19
+156,16
@@
public class REnSearch {
String filterName = cleanupWord(list.get(j).substring(pos+1));
\r
filterName = filterName.replace("*", ".*"); // setup for regular expression pattern match
\r
\r
String filterName = cleanupWord(list.get(j).substring(pos+1));
\r
filterName = filterName.replace("*", ".*"); // setup for regular expression pattern match
\r
\r
- if (tagNames.size() == 0)
\r
-
found =
false;
\r
+ if (tagNames.size() == 0
&& !negative
)
\r
+
return
false;
\r
\r
for (int i=0; i<tagNames.size(); i++) {
\r
boolean matches = Pattern.matches(filterName.toLowerCase(),tagNames.get(i).toLowerCase());
\r
\r
for (int i=0; i<tagNames.size(); i++) {
\r
boolean matches = Pattern.matches(filterName.toLowerCase(),tagNames.get(i).toLowerCase());
\r
- if (
matches
)
\r
-
found = tru
e;
\r
+ if (
!matches && !negative
)
\r
+
return fals
e;
\r
}
\r
}
\r
}
\r
}
\r
- if (negative)
\r
- return !found;
\r
- else
\r
- return found;
\r
+ return true;
\r
}
\r
\r
\r
}
\r
\r
\r
@@
-507,18
+498,6
@@
public class REnSearch {
if (todo.size() == 0 && resource.size() == 0 && searchPhrases.size() == 0)
\r
return true;
\r
\r
if (todo.size() == 0 && resource.size() == 0 && searchPhrases.size() == 0)
\r
return true;
\r
\r
- boolean returnTodo = false;
\r
- boolean returnResource = false;
\r
- boolean returnPhrase = false;
\r
-
\r
- if (todo.size() == 0)
\r
- returnTodo = true;
\r
- if (resource.size() == 0)
\r
- returnResource = true;
\r
- if (searchPhrases.size() == 0)
\r
- returnPhrase = true;
\r
-
\r
-
\r
n = conn.getNoteTable().getNote(n.getGuid(), true, true, false, false, false);
\r
\r
// Check for search phrases
\r
n = conn.getNoteTable().getNote(n.getGuid(), true, true, false, false, false);
\r
\r
// Check for search phrases
\r
@@
-533,12
+512,11
@@
public class REnSearch {
negative = false;
\r
phrase = phrase.substring(1);
\r
phrase = phrase.substring(0,phrase.length()-1);
\r
negative = false;
\r
phrase = phrase.substring(1);
\r
phrase = phrase.substring(0,phrase.length()-1);
\r
- if (text.indexOf(phrase)>=0) {
\r
- if (!negative)
\r
- returnPhrase = true;
\r
- }
\r
- if (text.indexOf(phrase)<0 && negative)
\r
- returnPhrase = true;
\r
+ if (text.indexOf(phrase)>=0 && negative) {
\r
+ return false;
\r
+ }
\r
+ if (text.indexOf(phrase) < 0 && !negative)
\r
+ return false;
\r
}
\r
\r
\r
}
\r
\r
\r
@@
-555,14
+533,13
@@
public class REnSearch {
if (value.startsWith("-"))
\r
desiredState = !desiredState;
\r
int pos = n.getContent().indexOf("<en-todo");
\r
if (value.startsWith("-"))
\r
desiredState = !desiredState;
\r
int pos = n.getContent().indexOf("<en-todo");
\r
- if (pos == -1 &&
value.startsWith("-") && (value.endsWith("*") || value.endsWith(":")
))
\r
- return
tru
e;
\r
+ if (pos == -1 &&
!value.startsWith("-"
))
\r
+ return
fals
e;
\r
if (pos > -1 && value.startsWith("-") && (value.endsWith("*") || value.endsWith(":")))
\r
return false;
\r
if (pos > -1 && value.startsWith("-") && (value.endsWith("*") || value.endsWith(":")))
\r
return false;
\r
- if (pos == -1)
\r
+ if (pos == -1
&& !value.startsWith("-")
)
\r
return false;
\r
return false;
\r
- if (value.endsWith("*"))
\r
- returnTodo = true;
\r
+ boolean returnTodo = false;
\r
while (pos > -1) {
\r
int endPos = n.getContent().indexOf("/>", pos);
\r
String segment = n.getContent().substring(pos, endPos);
\r
while (pos > -1) {
\r
int endPos = n.getContent().indexOf("/>", pos);
\r
String segment = n.getContent().substring(pos, endPos);
\r
@@
-571,11
+548,15
@@
public class REnSearch {
currentState = false;
\r
else
\r
currentState = true;
\r
currentState = false;
\r
else
\r
currentState = true;
\r
- if (desiredState == currentState)
\r
+ if (desiredState == currentState)
\r
+ returnTodo = true;
\r
+ if (value.endsWith("*") || value.endsWith(":"))
\r
returnTodo = true;
\r
\r
pos = n.getContent().indexOf("<en-todo", pos+1);
\r
}
\r
returnTodo = true;
\r
\r
pos = n.getContent().indexOf("<en-todo", pos+1);
\r
}
\r
+ if (!returnTodo)
\r
+ return false;
\r
}
\r
\r
// Check resources
\r
}
\r
\r
// Check resources
\r
@@
-590,13
+571,14
@@
public class REnSearch {
return false;
\r
for (int j=0; j<n.getResourcesSize(); j++) {
\r
boolean match = stringMatch(n.getResources().get(j).getMime(), resourceString, negative);
\r
return false;
\r
for (int j=0; j<n.getResourcesSize(); j++) {
\r
boolean match = stringMatch(n.getResources().get(j).getMime(), resourceString, negative);
\r
- if (!match)
\r
+ if (!match && !negative)
\r
+ return false;
\r
+ if (match && negative)
\r
return false;
\r
return false;
\r
- returnResource = true;
\r
}
\r
}
\r
\r
}
\r
}
\r
\r
- return
returnResource && returnTodo && returnPhras
e;
\r
+ return
tru
e;
\r
}
\r
\r
private boolean stringMatch(String content, String text, boolean negative) {
\r
}
\r
\r
private boolean stringMatch(String content, String text, boolean negative) {
\r