-
-
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
Readd query syntax validation #7418
Conversation
I tried your fix locally, it does not work, it still freezes when I paste text. Also you removed the key on enter pressed. |
I suppose that this issue is just to readd query syntax. In this case, I just rollback the original version and did not pull request my solution. If needed, I will pull request my solution to deal with GUI freezes. |
I have upload my solution to fix GUI freezes. |
// Use Thread Pool to control the match time | ||
private boolean isPatternMatched(Pattern pattern, String queryString) { | ||
boolean isMatched; | ||
Callable<Boolean> call = () -> { |
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.
You better use our BackGroundTask.wrap(...)
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.
Done! Please check it!
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.
Yep, works better now. No more freezing
The freezing is gone, but please readd the searching on enter. I'm just thinking if the code can be optimized a bit more. Maybe @tobiasdiez has an idea |
I have readded the searching on enter. Please check it. |
Note that we used Apache Lucene's query syntax. I am going to submit a pull request to the documentation to update it. I think, a regular expression cannot cover Lucence's full power as lucense is a context-senstitive grammar IMHO. I think, at the appropriate place, a try to parse the syntax by the selected fetcher could be tried. See here for an inspriation:
Thus, I am strongly against adding regex syntax checking here. I would ask for parsing the query for validation with the same method the query is parsed to query the online databases. |
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.
The code should use the "right" instance of AbstractQueryTransformer. It should enahnce these classes to provide proper feedback which part of the query is not valid.
The new explanation has been created as PR to the documentation: JabRef/user-documentation#348 |
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 agree, we should reuse the query parser from lucene and catch the ParseException to construct the error message. Otherwise this looks good to me!
Thanks for reimplementing this. Next time though please ask the developers first if it is reasonable to spent time on this. I was also of the opinion that the PR that removed this feature was merged to quickly, but please respect the decision of the core developer team. We try to strongly listen to users and other contributors, and take their suggestions into account. But in the end we are the ones that have to have the bigger picture in mind and have to maintain everything in the long run. Right now you spent time reimplementing the feature, and we spent time reviewing it - and probably in two weeks @DominikVoigt will create a PR redesigning the whole search interface and making this PR obsolete. That's a bit unfortunate use of time.
Nonetheless, let's get this in and hope it will be useful for the new interface as well.
boolean isMatched = true; | ||
|
||
try { | ||
BackgroundTask.wrap(() -> pattern.matcher(queryString.strip()).matches()) |
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.
This should only take a few milliseconds, so I wouldn't use a background task here.
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.
In this case, it's actually function matches()
takes a lot of time that make GUI freeze. When we input a long title, it will take about 2 mintues, which will make GUI freeze
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.
oooh that's surprising. The query parser is quicker, so this shouldn't be a problem any longer once use it.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
If you use the query parser instead of a regex, then it's good to go from my side.
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 need to merge a certain number PR due to some personal reasons....
We have some quick win ideas at https://github.com/koppor/jabref/labels/good%20first%20issue. For instance
JabRef#286 should be a quick win.
Actually, I indeed spent a lot of time dealing with this bug.
We spend a lot time implementing the new query syntax and discussing how to unfreeze JabRef in certain cases. When it is possible to use the "query parser" as @tobiasdiez suggested, it should be OK. It is IMHO just about deleting the regex code etc. Then this PR will probably only be some lines of code.
It should also be noted that we never released a version without the query syntax check. We merged the PR to avoid JabRef hanging when an invalid search query was inserted
Here, it should be noted, that the new search is already implemented. "Only" the feedback regarding the syntax is missing.
The syntax parsed here is NOT the syntax, JabRef uses for searching. As far as I see, the regex misses AND and OR. I do not see why we should come up with a self-made regex to parse Apache Lucene. In other words: The set of valid expressions detected in this PR is not the same set as the set of expression accepted by JabRef in the search. When this PR is merged as is, the feedback to the user is wrong in many cases. (This is also the reason why we removed the validation. Besides hanging it was not completely right.) Pleeeeeeeeeeeeeeeeeeeeease re-use the existing query parsing. I already pointed to code where it can be located from. When this is implemented, the set of validated queries is the same as JabRef takes as valid queries for searching. For users, it would be even more useful if the position of the first error in the query syntax would be shown. This should also possible with the already included libraries. |
Devcall-decision: We decided to close this PR since, we haven' heard about any change here. |
Readd the query syntax validation. Fixes #7411