silverstripe / silverstripe-fulltextsearch

Adds external full text search engine support to Silverstripe
BSD 3-Clause "New" or "Revised" License
44 stars 83 forks source link

Escape query chars #72

Open d-rivera-c-zz opened 9 years ago

d-rivera-c-zz commented 9 years ago

I get a 400 error in Solr if any of this characters are around

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

Sometimes it behaves well if the character is surrounded by letters instead of spaces, but should be better to escape them anyway. For example, searching for "Wellington/Petone" won't give an error, but "Wellington / Petone" will. I've added a preg_replace as a workaround, might be worth a look to include it as a fix in the module.

SolrIndex.php (line 376, function search() )

foreach ($query->search as $search) {
    $text = $search['text'];
    $text = preg_replace('/([\+\-!\(\)\{\}\[\]\^"~\*\?:\\/\|]|&&|\|\|)/', '\\\${1}', $text);   <---
    preg_match_all('/"[^"]*"|\S+/', $text, $parts);
robbieaverill commented 7 years ago

Needs revalidation

dhensby commented 6 years ago

I've had this issue- it's a problem with the solr library we are using being old and not correctly escaping special chars even though it has the feature.

micmania1 commented 6 years ago

@robbieaverill I haven't tried all chars but I can confirm it works with " so I assume others too. Likewise, AND and OR seem to trigger this too.

maxime-rainville commented 4 years ago

Need to validate if this is a problem with SS4.