Skip to content
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

Closed
wants to merge 8 commits into from
Closed

Conversation

Fu188
Copy link
Contributor

@Fu188 Fu188 commented Feb 3, 2021

Readd the query syntax validation. Fixes #7411

  • Change in CHANGELOG.md described (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

@Siedlerchr
Copy link
Member

I tried your fix locally, it does not work, it still freezes when I paste text. Also you removed the key on enter pressed.

@Siedlerchr Siedlerchr added the status: changes required Pull requests that are not yet complete label Feb 3, 2021
@Fu188
Copy link
Contributor Author

Fu188 commented Feb 4, 2021

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.

@Fu188
Copy link
Contributor Author

Fu188 commented Feb 4, 2021

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 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 = () -> {
Copy link
Member

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(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Please check it!

Copy link
Member

@Siedlerchr Siedlerchr Feb 5, 2021

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

@Fu188 Fu188 requested a review from Siedlerchr February 4, 2021 12:29
@Siedlerchr
Copy link
Member

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

CHANGELOG.md Outdated Show resolved Hide resolved
@Fu188
Copy link
Contributor Author

Fu188 commented Feb 6, 2021

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.

@Fu188 Fu188 requested a review from calixtus February 6, 2021 01:57
@koppor koppor requested a review from DominikVoigt February 7, 2021 21:48
@koppor
Copy link
Member

koppor commented Feb 7, 2021

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:

return this.performSearch(parser.parse(searchQuery, NO_EXPLICIT_FIELD));

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.

Copy link
Member

@koppor koppor left a 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.

@koppor
Copy link
Member

koppor commented Feb 7, 2021

Note that this PR in its current state just reverted the quick fix of #7391. Note the following text of that PR:

grafik

I am so sorry that I did not highlight this text in #7411. I also added the screenshot there.

@koppor
Copy link
Member

koppor commented Feb 8, 2021

The new explanation has been created as PR to the documentation: JabRef/user-documentation#348

Copy link
Member

@tobiasdiez tobiasdiez left a 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())
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

@koppor
Copy link
Member

koppor commented Feb 8, 2021

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.

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

in two weeks @DominikVoigt will create a PR redesigning the whole search interface and making this PR obsolete.

Here, it should be noted, that the new search is already implemented. "Only" the feedback regarding the syntax is missing.

Nonetheless, let's get this in and hope it will be useful for the new interface as well.

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.

@calixtus
Copy link
Member

Devcall-decision: We decided to close this PR since, we haven' heard about any change here.
In fact, @DominikVoigt is already working on a different solution, using the transformators to provide feedback about parsing the query strings. So we would like to ask you to be patient for his work.

@calixtus calixtus closed this Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add best query syntax validation
5 participants