简体   繁体   English

如何在模糊搜索查询中处理特殊字符

[英]How to handle special characters in fuzzy search query

So my solr query is implemented in two parts,first query does an exact search if there are no results found for exact then it goes to the second query that does a fuzzy search. 因此,我的Solr查询分为两个部分,第一个查询进行精确搜索(如果没有找到精确结果),然后转到第二个进行模糊搜索的查询。 every things works fine but in situations like-->A user enters "burg +" So in exact search no records will come,so second query is called to do a fuzzy search.Now comes the problem my fuzzy query does not understand special characters like +,-* which throws and error.If i dont pass special characters it works fine. 一切正常,但在->用户输入“ burg +”的情况下,因此在精确搜索中不会出现任何记录,因此调用第二个查询进行模糊搜索。现在出现了我的模糊查询无法理解特殊字符的问题像+,-*会引发错误。如果我不传递特殊字符,它将正常工作。 But in real world a user can put characters with their search,which will throw an error. 但是在现实世界中,用户可以在搜索中放入字符,这将引发错误。 Now iam stuck in this and dont know how to resolve this issue. 现在,iam陷入其中,不知道如何解决此问题。 This is how my exact search query looks like 这就是我的确切搜索查询的样子

$query1="(business_name:$data*^100 OR city_name:$data*^1 OR   
locality_name:$data*^6 OR business_search_tag_name:$data*^8 OR 
type_name:$data*^7) AND (business_active_flag:1) AND 
(business_visible_flag:1) AND (delete_status_businessmasters:0)";

This is how my fuzzy query looks like 这就是我的模糊查询的样子

$query2='(_query_:%20"{!complexphrase%20qf=business_name^100+type_name^0.4+locality_name^6%27}%20'.$url_new.')AND(business_active_flag:1)AND(business_point:[1.5 TO 2.0])&q.op=AND&wt=json&indent=true';

This is the error iam getting 这是我得到的错误

 Cannot parse ' must~1 *~N': '*' or '?' not allowed as first character in WildcardQuery

Iam new to solr and dont know how to tackle this situation. Iam是Solr的新手,不知道如何解决这种情况。

Details of what iam using IAM使用的详细信息

Solrphpclient Solrphpclient

php PHP

solr 4.9 索尔4.9

ok so i see that you are using solrphpclient.You need to make changes in the service.php file so that these special characters get replaced to either blank or what ever you want. 好的,所以我看到您使用的是solrphpclient。您需要在service.php文件中进行更改,以便将这些特殊字符替换为空白或任何您想要的字符。 This will take care of the problem you are facing 这样可以解决您面临的问题

$params=str_replace("%", "", $params);
$params=str_replace("*", "", $params);
$params=str_replace("&", "", $params);

you need to put this in the search function or inside you custom function which i assume you are using for the fuzzy query 您需要将其放入搜索功能或自定义功能中,我假设您正在使用模糊查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM