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

Add tokenStart and tokenEnd to query #9

Merged
merged 17 commits into from
Jul 22, 2022
Merged

Add tokenStart and tokenEnd to query #9

merged 17 commits into from
Jul 22, 2022

Conversation

North101
Copy link
Contributor

@North101 North101 commented Jul 1, 2022

I wanted to be able to offer auto complete suggestions for my search query and for that I needed to know the location of the Query to figure out if it was at my cursor position.

This PR adds the start / end position of the Query relative to input.

@North101
Copy link
Contributor Author

North101 commented Jul 1, 2022

I also would like to make the <exp> part of field:<exp> and field=<exp> optional. Though this is would be a breaking change. If you don't want that I'm happy to just keep it in my fork

Copy link
Owner

@isoos isoos left a comment

Choose a reason for hiding this comment

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

I think this is a good feature to add, but please:

  • add tests, the more the better to see (a) what is now available and (b) how to use/access it (it can be a new file)
  • explain a bit how the optional exp is breaking, and maybe also add tests there too with comments
  • also update the changelog and bump the version

lib/src/ast.dart Outdated Show resolved Hide resolved
@North101
Copy link
Contributor Author

North101 commented Jul 2, 2022

  • add tests, the more the better to see (a) what is now available and (b) how to use/access it (it can be a new file)

Sure. I didn't want to write them until you gave it an ok :P

  • explain a bit how the optional exp is breaking, and maybe also add tests there too with comments

It was failing one test but I was able to make a minor change or to get it to pass. Another reason it might be breaking is because the following used to error but now parses because it used to expect something after the ::

field: AND somethingelse
  • also update the changelog and bump the version

Cool. Will do after the tests

@North101
Copy link
Contributor Author

North101 commented Jul 2, 2022

I've changed FieldScopeQuery and FieldCompareQuery to take TextQuery instead of String as I found I needed to know the start/end index of the field. I added a getter to keep them backwards compatible.

@isoos
Copy link
Owner

isoos commented Jul 2, 2022

I've changed FieldScopeQuery and FieldCompareQuery to take TextQuery instead of String as I found I needed to know the start/end index of the field. I added a getter to keep them backwards compatible.

I will look the code later, but if this is a change that could possibly break more than one API, maybe it is worth doing it by bumping the major version and documenting what has been changed in a breaking way. Not yet sure if it is the case here, I'm just stating that it is not off the table.

@North101
Copy link
Contributor Author

North101 commented Jul 2, 2022

If you're happy with a major version bump then that'd make things easier.

@isoos
Copy link
Owner

isoos commented Jul 2, 2022

If you're happy with a major version bump then that'd make things easier.

I don't mind, just make sure to add plenty of notes in the changelog to help users migrate.

Copy link
Owner

@isoos isoos left a comment

Choose a reason for hiding this comment

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

On a high level I like this, but I'd like to do a deep dive into it before going forward with it. Unfortunately I have a few busy days before me, and it may happen only sometime next week :(

lib/src/ast.dart Outdated Show resolved Hide resolved
lib/src/grammar.dart Show resolved Hide resolved
@North101
Copy link
Contributor Author

North101 commented Jul 9, 2022

On a high level I like this, but I'd like to do a deep dive into it before going forward with it. Unfortunately I have a few busy days before me, and it may happen only sometime next week :(

No prob. I'm using this branch in my project for now so no rush

Copy link
Owner

@isoos isoos left a comment

Choose a reason for hiding this comment

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

Thank you for all the changes you've done! Only one big question remains about the type of the operator.

For the other two, I'm happy to do them, but I'm unsure which name to use for the span field/class. Any preference?

final String operator;
class FieldCompareQuery extends Query {
final TextQuery field;
final TextQuery operator;
Copy link
Owner

Choose a reason for hiding this comment

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

Is the change from String to TextQuery for the operator field correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could help figure out where the operator is.

e.g. all of these are valid:

field=value
field = value
field    =    value

Copy link
Owner

Choose a reason for hiding this comment

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

I think this should be a separate FieldOperator extends Query type, with text or value + position. The TextQuery has isExactMatch which doesn't make sense for this field, and it doesn't feel right. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it make sense to have FieldCompareQuery.field, FieldCompareQuery .operator and FieldScope.operator all share the same class. e.g. something like

class FieldElementQuery extends Query {
  final String text;
  const FieldElementQuery({
    required this.text,
    required super.position,
  });

  @override
  String toString({bool debug = false}) =>
      _debug(debug, text);
}

Copy link
Contributor Author

@North101 North101 Jul 21, 2022

Choose a reason for hiding this comment

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

Or... Remove isExactMatch from TextQuery as its only ever used for PhraseQuery?

I think this is what I prefer but I'm happy to for whatever you suggest

Copy link
Owner

Choose a reason for hiding this comment

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

That is a good solution too!

lib/src/ast.dart Outdated Show resolved Hide resolved
lib/src/ast.dart Show resolved Hide resolved
Copy link
Owner

@isoos isoos left a comment

Choose a reason for hiding this comment

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

This looks good! One small nit for the documentation part.

lib/src/ast.dart Show resolved Hide resolved
@isoos isoos merged commit 89818e9 into isoos:master Jul 22, 2022
@isoos
Copy link
Owner

isoos commented Jul 22, 2022

I'm really happy with the current state of the PR, thank you for idea and all the small follow-ups!
Do you have anything else in the works, or shall I release it?

@North101
Copy link
Contributor Author

North101 commented Jul 22, 2022

That's it for me. Thanks for the library! I've been able to make an advanced SQL db search with it and with this PR it now gives contextual suggests!
Screenshot_20220629-165430
Screenshot_20220629-165450
Screenshot_20220629-165701

@isoos
Copy link
Owner

isoos commented Jul 22, 2022

Great features! :)

Published as 2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants