projectblacklight / blacklight_advanced_search

Advanced search plugin for Blacklight
http://projectblacklight.org
Other
24 stars 25 forks source link

NoMethodError: undefined method `collect' for "()"@158:Parslet::Slice #101

Open dkinzer opened 5 years ago

dkinzer commented 5 years ago

So we’re getting a failure on from blacklight_advanced_search whenever we search anything with empty parens in it like “()” as the smallest case example. Anyone else see this… We are on the latest blacklight_advanced_search gem but we suspect issue goes back to other versions…. The error is NoMethodError: undefined method `collect' for "()"@158:Parslet::Slice and it’s getting thrown here


[GEM_ROOT]/bundler/gems/blacklight_advanced_search-9c23f0e9aad6/lib/parsing_nesting/tree.rb:40:in `to_node_tree'
38     elsif tree.is_a? Hash
39       if list = tree[:list]
40         List.new(list.collect { |i| to_node_tree(i, query_parser) }, query_parser)
41       elsif tree.has_key?(:and_list)
42         AndList.new(tree[:and_list].collect { |i| to_node_tree(i, query_parser) }, query_parser)```
jrochkind commented 5 years ago

BAS tries to parse a boolean query, yes. This was a “feature”/requirement.

There’s no way to do that without making some ‘natural language’ things fail. There’s no way to fix this. See also recent discussion about “Portland OR bicycles”.

If you put the thing with parens in double quotes, it’ll probably work. (although the parens are probably stripped out by your Solr query parser anyway and have no effect on results).

print() will fail, but I bet "print()" will succeed.

I don’t know if there’s anything that can be done about this. I suppose there could be a feature to toggle off boolean query parsing, and just treat everything entered as a literal.

If you have boolean query parsing -- which was originally a requirement/goal/feature of this (now very old) library -- there are necessarily going to be things that don't parse.

Although I suppose it would also be better if you got an actual parse error as an exception here, instead of a kind of random uncaught exception. I'm not sure it's worth the effort to make that so, I don't think it will get you any closer to something you actually want.