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

query dont check if String Text OR Text OR Text is exist one of them in List[i] #1

Open
thewama33 opened this issue Sep 16, 2019 · 6 comments

Comments

@thewama33
Copy link

how to check if String Text OR Text OR Text is exist one of them in List[i]

 for (int i = 0; i < list.length; i++) {
      
      if (list[i] == parseQuery(input)) {
        print(list[i]);
      }
    }
@thewama33 thewama33 changed the title how to check if String Text OR Text OR Text is exist one of them in List[i] query dont check if String Text OR Text OR Text is exist one of them in List[i] Sep 17, 2019
@isoos
Copy link
Owner

isoos commented Sep 17, 2019

After you have the parsed Query object, you'll need to write your own rules for it, e.g.

main() {
  final list = <String>['a', 'text3'];
  final query = parseQuery('text OR text2 OR text3');
  final matches = _evalQuery(query, list);
  print('matched: $matches');
}

bool _evalQuery(Query query, List<String> list) {
  if (query is OrQuery) {
    return query.children.any((q) => _evalQuery(q, list));
  } else if (query is TextQuery) {
    return list.contains(query.text);
  } else {
    throw Exception('Unknown query type: $query');
  }
}

Does this help?

@thewama33
Copy link
Author

it works but didn't solve what I need, the point is if Text3 exists, print the Text3 from the list, your solution is to print true if exist

@isoos
Copy link
Owner

isoos commented Sep 18, 2019

You could return a composite object that has the boolean flag and the extracted value. It makes it a bit more complex though, but the base principle remains the same.

@thewama33
Copy link
Author

why don't you make full documentation for the library, your example is not totally clear for the use and also it's not really clear how to use it with lists unfortunately

@isoos
Copy link
Owner

isoos commented Sep 21, 2019

Yeah, it is lacking documentation, but I always welcome PRs :)

@thewama33
Copy link
Author

that's gonna be great @isoos if did that, just last one thing I may need you give hand with ,

I have list of Documents comes from Firestore and saved in List

I have 2 lists
[1] List for All Documents
[2] List for Filtered Documents
as you said before Text1 OR Text2 OR Text3
could you please tell me how to use query to Put the Searched text Text2 , Text3 if exist in the list

i've tried many times but didn't work for me with the library

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

No branches or pull requests

2 participants