Smile-SA / smile-magento-elasticsearch

Magento ElasticSearch Implementation
151 stars 91 forks source link

Failed to parse query with a slash - suggest action #66

Closed mbijnsdorp closed 7 years ago

mbijnsdorp commented 8 years ago

When you have a / in the suggest query, it fails with the following exception:

"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[index][0]: SearchParseException[[index][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"filtered\":{\"query\":{\"bool\":{\"must\":[{\"function_score\":{\"query\":{\"bool\":{\"must\":[{\"multi_match\":{\"query\":\"pants\\/\",\"type\":\"best_fields\",\"minimum_should_match\":\"100%\",\"fields\":[\"autocomplete_nl.edge_ngram_front\"],\"fuzziness\":\"0.5\",\"prefix_length\":\"1\",\"max_expansions\":\"20\",\"analyzer\":\"whitespace\"}}],\"should\":[{\"multi_match\":{\"query\":\"pants\\/\",\"type\":\"best_fields\",\"tie_breaker\":1,\"fields\":[\"autocomplete_nl.edge_ngram_front\"],\"analyzer\":\"analyzer_nl\"}}]}},\"functions\":[{\"filter\":{\"query\":{\"query_string\":{\"query\":\"pants\\/\",\"default_field\":\"autocomplete_nl.whitespace\"}}},\"boost_factor\":10}]}}]}},\"filter\":{\"bool\":{\"must\":[{\"terms\":{\"visibility\":[3,4]}},{\"terms\":{\"status\":[1]}},{\"terms\":{\"in_stock\":[1]}},{\"terms\":{\"store_id\":[1]}}],\"_cache\":true}}}},\"fields\":[\"entity_id\"],\"track_scores\":true,\"sort\":[{\"_score\":\"desc\"}],\"from\":0,\"size\":\"3\"}]]]; nested: QueryParsingException[[index] Failed to parse query [pants/]]; nested: ParseException[Cannot parse 'pants/': Lexical error at line 1, column 7.  Encountered: <EOF> after : \"\"]; nested: TokenMgrError[Lexical error at line 1, column 7.  Encountered: <EOF> after : \"\"]; }]","status":400}

The error lead me to this issue in the elasticsearch repo: https://github.com/elastic/elasticsearch/issues/2980

Escaping the query seems the most logical solution to this, however I don't know this module that well. I tested with escaping the query when it's set in Smile_ElasticSearch_Model_Resource_Engine_Elasticsearch_Query_Abstract::setFulltextQuery($query) which worked well for me.

For some reason this exception doesn't occur when I search on the same query.

If you agree with this, I can make a PR.

mbijnsdorp commented 8 years ago

@romainruaud Could you take a look at this? I'm still stuck with this issue and would like to get it solved without having to do a lot of rewrites.

romainruaud commented 8 years ago

Hello @mbijnsdorp, this is a known issue and currently fixed in our internal version of the module. This version will be released soon and also add a lot of feature. However, this version is under-prioritized versus the Magento2 version of the module.

Best regards,

mbijnsdorp commented 8 years ago

Cool, thanks for the update.

simbus82 commented 8 years ago

Hi @romainruaud, but why you can't add a "development" or "WIP" (work in progress) branch here in Github? I think we can help to test and maybe solve some problem, and we can have latest (even if untested) features.

Thanks!

mbijnsdorp commented 8 years ago

Hey @romainruaud, what is soon? It's over 2 months now and there's still no 1.4 release.

romainruaud commented 8 years ago

Hello @mbijnsdorp and sorry for the delay. As explained before, Magento 1 is not our priority and we are now working full-time on Magento2 version of the module.

I have pushed the 1.4 branch on this repository. The branch includes up-to-date documentation regarding the new features of the module. However, please consider this branch as WIP since it has not been merged into the master (which would imply that it is now stable).

Regards.

romainruaud commented 7 years ago

Fixed in 1.4.0