-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch colors of search icon for the two search modes #3871
Changes from 4 commits
183679c
57fe659
4c45545
cb56ae4
f616cb5
0b8f8b3
47efd62
0efe1f8
49099af
b9e6111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,20 @@ | |
|
||
import org.jabref.model.strings.StringUtil; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class SearchRules { | ||
|
||
private SearchRules() { | ||
} | ||
|
||
private static final Pattern simpleExpression = Pattern.compile("(\\w|\\d|\\s)*"); | ||
|
||
/** | ||
* Returns the appropriate search rule that fits best to the given parameter. | ||
*/ | ||
public static SearchRule getSearchRuleByQuery(String query, boolean caseSensitive, boolean regex) { | ||
if (StringUtil.isBlank(query)) { | ||
if (isSimpleQuery(query)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reads good! |
||
return new ContainBasedSearchRule(caseSensitive); | ||
} | ||
|
||
|
@@ -25,6 +29,10 @@ public static SearchRule getSearchRuleByQuery(String query, boolean caseSensitiv | |
} | ||
} | ||
|
||
private static boolean isSimpleQuery(String query) { | ||
return StringUtil.isBlank(query) || simpleExpression.matcher(query).matches(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really need both? The current regex has a star ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, that sounds reasonable. I removed the StringUtil dependency and as far as I can see there is no difference in the search. |
||
} | ||
|
||
private static SearchRule getSearchRule(boolean caseSensitive, boolean regex) { | ||
if (regex) { | ||
return new RegexBasedSearchRule(caseSensitive); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should regex really be treated as grammar-based search? I would not treat it like that, because regex search is orthogonal to grammar-based search. One can activate it in addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the documentation: https://help.jabref.org/en/Search#search-modes they are listed under the heading of "advanced search". But I can easily change that of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the help accordingly to also reflect that regular expressions are orthogonal. 😇
Could you additionally add a comment there that this is the "Advanced Search" described in the help? I know, this contradicts DDD, but I think, it is OK in this place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I adapted the code accordingly.