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. 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. 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. This is how my exact search query looks like
所以我的solr查询分为两部分实现,如果没有找到精确的结果,则第一个查询进行精确搜索,然后进入进行模糊搜索的第二个查询。每件事情都很好但是在 - >用户输入“burg +”的情况下所以在精确搜索中没有记录会出现,所以第二个查询被调用来进行模糊搜索。现在问题是我的模糊查询不理解特殊字符像+, - *抛出和错误。如果我没有传递特殊字符,它工作正常。但在现实世界中,用户可以在搜索中放置字符,这会引发错误。现在我陷入困境,不知道如何解决这个问题。这就是我的确切搜索查询的样子
$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.
我刚接触solr并且不知道如何解决这种情况。
Details of what iam using
我使用的详细信息
Solrphpclient
php
solr 4.9
1 个解决方案
#1
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. This will take care of the problem you are facing
好的,所以我看到你正在使用solrphpclient。你需要在service.php文件中进行更改,以便这些特殊字符被替换为空白或任何你想要的。这将解决您面临的问题
$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
你需要把它放在搜索功能或你自定义函数里面,我假设你用于模糊查询
#1
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. This will take care of the problem you are facing
好的,所以我看到你正在使用solrphpclient。你需要在service.php文件中进行更改,以便这些特殊字符被替换为空白或任何你想要的。这将解决您面临的问题
$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
你需要把它放在搜索功能或你自定义函数里面,我假设你用于模糊查询