ฉันกำลังใช้ solr กับ Ruby บนราง ทุกอย่างทำงานได้ดี ฉันแค่ต้องรู้ว่ามีโค้ดที่มีอยู่เพื่อฆ่าเชื้ออินพุตของผู้ใช้หรือไม่ เช่น ข้อความค้นหาที่ขึ้นต้นด้วย ? หรือ *
แบบสอบถามการฆ่าเชื้อของ Solr
คำตอบ (2)
ฉันไม่รู้รหัสใด ๆ ที่ทำสิ่งนี้ แต่ในทางทฤษฎีแล้วสามารถทำได้โดยดูที่ การแยกวิเคราะห์โค้ดใน Lucene และค้นหา throw new ParseException
(ตรงกันเพียง 16 รายการเท่านั้น!)
ในทางปฏิบัติ ฉันคิดว่าคุณควรจับข้อยกเว้น solr ในโค้ดของคุณและแสดงข้อความค้นหาที่ไม่ถูกต้องหรืออะไรทำนองนั้นจะดีกว่า
แก้ไข: นี่คือน้ำยาฆ่าเชื้อสองสามตัว:
- http://pivotallabs.com/users/zach/blog/articles/937-sanitizing-solr-requests
- http://github.com/jvoorhis/lucene_query
- http://e-mats.org/2010/01/escaping-Characters-in-a-solr-query-solr-url/
person
Mauricio Scheffer
schedule
16.07.2009
หากคุณใช้ Solarium กับ PHP คุณสามารถใช้เมธอด Solarium_Escape::term()
ได้
/**
* Escape a term
*
* A term is a single word.
* All characters that have a special meaning in a Solr query are escaped.
*
* If you want to use the input as a phrase please use the {@link phrase()}
* method, because a phrase requires much less escaping.\
*
* @link http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
*
* @param string $input
* @return string
*/
static public function term($input)
{
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
return preg_replace($pattern, '\\\$1', $input);
}
person
crmpicco
schedule
30.09.2013