c++搜索文本 n 布尔模式
基本上有两个问题。
1. 是否有一个 C++ 库可以像 mysql 一样进行全文布尔搜索。例如,
假设我有:
string text = "this is my phrase keywords test with boolean query.";
string booleanQuery = "\"my phrase\" boolean -test -\"keywords test\" OR ";
booleanQuery += "\"boolean search\" -mysql -sql -java -php"b
//where quotes ("") contain phrases, (-) is NOT keyword and OR is logical OR.
If answer to first is no, then;
2. Is it possible to search a phrase in text. e.g.,
string text =//same as previous
string keyword = "\"my phrase\"";
//here what's the best way to search for my phrase in the text?
basically have two questions.
1. Is there a c++ library that would do full text boolean search just like in mysql. E.g.,
Let's say I have:
string text = "this is my phrase keywords test with boolean query.";
string booleanQuery = "\"my phrase\" boolean -test -\"keywords test\" OR ";
booleanQuery += "\"boolean search\" -mysql -sql -java -php"b
//where quotes ("") contain phrases, (-) is NOT keyword and OR is logical OR.
If answer to first is no, then;
2. Is it possible to search a phrase in text. e.g.,
string text =//same as previous
string keyword = "\"my phrase\"";
//here what's the best way to search for my phrase in the text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TR1 有一个正则表达式类(派生自
Boost::regex
)。它与您上面使用的不太一样,但相当接近。Boost::phoenix
和Boost::Spirit
也提供类似的功能,但对于第一次尝试,Boost/TR1 正则表达式类可能是更好的选择。TR1 has a regex class (derived from
Boost::regex
). It's not quite like you've used above, but reasonably close.Boost::phoenix
andBoost::Spirit
also provide similar capabilities, but for a first attempt the Boost/TR1 regex class is probably a better choice.至于第二点:
string
类确实有一个方法find
,请参见http://www.cppreference.com/wiki/string/findAs to the 2nd point:
string
class does have a methodfind
, see http://www.cppreference.com/wiki/string/find当然有,试试 Spirit:
http://boost-spirit.com/home/
Sure there is, try Spirit:
http://boost-spirit.com/home/