query icon indicating copy to clipboard operation
query copied to clipboard

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

Open thewama33 opened this issue 6 years ago • 6 comments

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 avatar Sep 16 '19 21:09 thewama33

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?

isoos avatar Sep 17 '19 18:09 isoos

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

thewama33 avatar Sep 18 '19 04:09 thewama33

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.

isoos avatar Sep 18 '19 05:09 isoos

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

thewama33 avatar Sep 20 '19 18:09 thewama33

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

isoos avatar Sep 21 '19 05:09 isoos

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

thewama33 avatar Sep 21 '19 18:09 thewama33