{"id":521,"date":"2008-08-04T00:00:00","date_gmt":"2008-08-03T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=521"},"modified":"2011-07-15T09:22:44","modified_gmt":"2011-07-15T01:22:44","slug":"lucene-query-parser","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=521","title":{"rendered":"Lucene Query Parser"},"content":{"rendered":"<p><P>Lucene Query Parser <\/P><br \/>\n<P>\u7ffb\u8bd1\u8fd9\u7bc7\u6587\u7ae0\u7684\u521d\u8877\u662f\u5e0c\u671b\u80fd\u66f4\u7cfb\u7edf\u7684\u7406\u89e3Lucene\u7684\u7528\u6cd5\uff0c\u540c\u65f6\u8bd5\u8bd5\u81ea\u5df1\u7684\u7ffb\u8bd1\u6c34\u5e73\uff1a\uff09<\/P><br \/>\n<P>\u539f\u6587\uff1a<A href=\"http:\/\/jakarta.apache.org\/lucene\/docs\/queryparsersyntax.html\">http:\/\/jakarta.apache.org\/lucene\/docs\/queryparsersyntax.html<\/A><\/P><br \/>\n<P>\u6982\u8ff0<\/P><br \/>\n<P>\u867d\u7136Lucene\u63d0\u4f9b\u7684API\u5141\u8bb8\u4f60\u521b\u5efa\u4f60\u81ea\u5df1\u7684Query\uff08\u67e5\u8be2\u8bed\u53e5\uff09\uff0c\u4f46\u5b83\u540c\u65f6\u4e5f\u901a\u8fc7Query Parser\uff08\u67e5\u8be2\u5206\u6790\u5668\uff09\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u67e5\u8be2\u8bed\u8a00\u3002<\/P><br \/>\n<P>\u8fd9\u4e2a\u9875\u9762\u63d0\u4f9b\u7684\u662fLucene\u7684Query Parser\u7684\u8bed\u6cd5\u4ecb\u7ecd\uff1a\u4e00\u4e2a\u53ef\u901a\u8fc7\u7528JavaCC\u628a\u4e00\u4e2a\u5b57\u7b26\u4e32\u89e3\u91ca\u6210\u4e3aLucene\u7684\u67e5\u8be2\u8bed\u53e5\u7684\u89c4\u5219\u3002<\/P><br \/>\n<P>\u5728\u9009\u62e9\u4f7f\u7528\u88ab\u63d0\u4f9b\u7684Query Parser\u524d\uff0c\u8bf7\u8003\u8651\u4e00\u4e0b\u51e0\u70b9\uff1a<\/P><br \/>\n<P>1\u3001\u5982\u679c\u4f60\u662f\u901a\u8fc7\u7f16\u5199\u7a0b\u5e8f\u751f\u6210\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u7136\u540e\u901a\u8fc7Query Parser\u5206\u6790\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u8ba4\u771f\u7684\u8003\u8651\u662f\u5426\u8be5\u76f4\u63a5\u5229\u7528Query\u7684API\u6784\u9020\u4f60\u7684\u67e5\u8be2\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cQuery Parser\u662f\u4e3a\u90a3\u4e9b\u4eba\u5de5\u8f93\u5165\u7684\u6587\u672c\u6240\u8bbe\u8ba1\u7684\uff0c\u800c\u4e0d\u662f\u4e3a\u4e86\u7a0b\u5e8f\u751f\u6210\u7684\u6587\u672c\u3002<\/P><br \/>\n<P>2\u3001\u672a\u5206\u8bcd\u7684\u5b57\u6bb5\u6700\u597d\u76f4\u63a5\u52a0\u5230Query\u4e2d\uff0c\u800c\u4e0d\u8981\u901a\u8fc7Query Parser\u3002\u5982\u679c\u4e00\u4e2a\u5b57\u6bb5\u7684\u503c\u662f\u7531\u7a0b\u5e8f\u751f\u6210\u7684\uff0c\u90a3\u4e48\u9700\u8981\u4e3a\u8fd9\u4e2a\u5b57\u6bb5\u751f\u6210\u4e00\u4e2aQuery Clause\uff08\u67e5\u8be2\u5b50\u53e5\uff09\u3002Query Parser\u6240\u7528\u7684Analyzer\u662f\u4e3a\u8f6c\u6362\u4eba\u5de5\u8f93\u5165\u7684\u6587\u672c\u4e3a\u5206\u8bcd\u7684\u3002\u800c\u7a0b\u5e8f\u751f\u6210\u7684\u503c\uff0c\u6bd4\u5982\u65e5\u671f\u3001\u5173\u952e\u5b57\u7b49\uff0c\u4e00\u822c\u90fd\u7531\u7a0b\u5e8f\u76f4\u63a5\u751f\u6210\uff08\uff1f\uff09\u3002<\/P><br \/>\n<P>3\u3001\u5728\u4e00\u4e2a\u67e5\u8be2\u8868\u5355\u91cc\uff0c\u901a\u5e38\u662f\u6587\u672c\u7684\u5b57\u6bb5\u5e94\u8be5\u4f7f\u7528Query Parser\u3002\u6240\u6709\u5176\u4ed6\u7684\uff0c\u6bd4\u5982\u65e5\u671f\u8303\u56f4\u3001\u5173\u952e\u5b57\u7b49\u7b49\uff0c\u6700\u597d\u662f\u901a\u8fc7Query API\u76f4\u63a5\u52a0\u5165\u5230Query\u4e2d\u3002\u4e00\u4e2a\u6709\u6709\u9650\u4e2a\u503c\u7684\u5b57\u6bb5\uff0c\u6bd4\u5982\u901a\u8fc7\u4e0b\u62c9\u8868\u5355\u5b9a\u4e49\u7684\u90a3\u4e9b\uff0c\u4e0d\u5e94\u8be5\u88ab\u52a0\u5230\u67e5\u8be2\u5b57\u4e32\u4e2d\uff08\u540e\u9762\u4f1a\u5206\u6790\u5230\uff09\uff0c\u800c\u5e94\u8be5\u88ab\u6dfb\u52a0\u4e3a\u4e00\u4e2aTermQuery\u5b50\u53e5\u3002<\/P><br \/>\n<P>\u5206\u8bcd<\/P><br \/>\n<P>\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u662f\u6709\u5206\u8bcd\u548c\u64cd\u4f5c\u7b26\u7ec4\u6210\u7684\u3002\u8fd9\u91cc\u6709\u4e24\u79cd\u7c7b\u578b\u7684\uff1a\u5355\u4e2a\u7684\u5206\u8bcd\u548c\u77ed\u8bed\u3002<\/P><br \/>\n<P>\u4e00\u4e2a\u5355\u4e00\u5206\u8bcd\u5c31\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5355\u8bcd\uff0c\u6bd4\u5982&#8221;test&#8221;\u6216&#8221;hello&#8221;\u3002<\/P><br \/>\n<P>\u4e00\u4e2a\u77ed\u8bed\u5c31\u662f\u4e00\u7ec4\u88ab\u53cc\u5f15\u53f7\u5305\u62ec\u7684\u5355\u8bcd\uff0c\u6bd4\u5982&#8221;hello dolly&#8221;\u3002<\/P><br \/>\n<P>\u591a\u4e2a\u5206\u8bcd\u53ef\u4ee5\u7528\u5e03\u5c14\u64cd\u4f5c\u7b26\u7ec4\u5408\u8d77\u6765\u5f62\u6210\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u67e5\u8be2\u8bed\u53e5\uff08\u4e0b\u9762\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\uff09\u3002<\/P><br \/>\n<P>\u6ce8\u610f\uff1a\u7528\u4e8e\u5efa\u7acb\u7d22\u5f15\u7684\u5206\u6790\u5668\uff08Analyzer\uff09\u5c06\u88ab\u7528\u4e8e\u89e3\u91ca\u67e5\u8be2\u8bed\u53e5\u4e2d\u7684\u5206\u8bcd\u548c\u77ed\u8bed\u3002\u56e0\u6b64\uff0c\u5408\u7406\u7684\u9009\u62e9\u4e00\u4e2a\u5206\u6790\u5668\u662f\u5f88\u91cd\u8981\u7684\uff0c\u5f53\u7136\u8fd9\u4e0d\u4f1a\u5f71\u54cd\u4f60\u5728\u67e5\u8be2\u8bed\u53e5\u4e2d\u4f7f\u7528\u7684\u5206\u8bcd\u3002<\/P><br \/>\n<P>\u5b57\u6bb5<\/P><br \/>\n<P>Lucene\u652f\u6301\u5b57\u6bb5\u6570\u636e\u3002\u5f53\u6267\u884c\u4e00\u4e2a\u641c\u7d22\u65f6\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6216\u8005\u4f7f\u7528\u9ed8\u8ba4\u7684\u5b57\u6bb5\u3002\u5b57\u6bb5\u7684\u540d\u5b57\u548c\u9ed8\u8ba4\u7684\u5b57\u6bb5\u662f\u53d6\u51b3\u4e8e\u5b9e\u73b0\u7ec6\u8282\u7684\u3002<\/P><br \/>\n<P>\u4f60\u53ef\u4ee5\u641c\u7d22\u4efb\u4f55\u5b57\u6bb5\uff0c\u505a\u6cd5\u662f\u8f93\u5165\u5b57\u6bb5\u540d\u79f0\uff0c\u7ed3\u5c3e\u8ddf\u4e0a\u4e00\u4e2a\u5192\u53f7 &#8220;:&#8221; \uff0c \u7136\u540e\u8f93\u5165\u4f60\u60f3\u67e5\u627e\u7684\u5206\u8bcd\u3002<\/P><br \/>\n<P>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u8ba9\u6211\u4eec\u5047\u8bbeLucene\u7684\u7d22\u5f15\u5305\u542b\u4e24\u4e2a\u5b57\u6bb5\uff0c\u6807\u9898\u548c\u6b63\u6587\uff0c\u6b63\u6587\u662f\u9ed8\u8ba4\u5b57\u6bb5\u3002\u5982\u679c\u4f60\u60f3\u6807\u9898\u4e3a &#8220;The Right Way&#8221; \u5e76\u4e14\u6b63\u6587\u5305\u542b\u6587\u672c &#8220;don&#8217;t go this way&#8221;\u7684\u8bb0\u5f55\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\uff1a<\/P><br \/>\n<P>&nbsp; title:&#8221;The Right Way&#8221; AND text:go&nbsp; <\/P><br \/>\n<P>\u6216\u8005<\/P><br \/>\n<P>&nbsp; title:&#8221;Do it right&#8221; AND right<\/P><br \/>\n<P>\u7531\u4e8e\u6b63\u6587\u662f\u9ed8\u8ba4\u5b57\u6bb5\uff0c\u6240\u4ee5\u5b57\u6bb5\u6307\u793a\u5c31\u6ca1\u6709\u5fc5\u8981\u4e86\u3002<\/P><br \/>\n<P>\u6ce8\u610f\uff1a\u5b57\u6bb5\u7684\u641c\u7d22\u503c\u53ea\u80fd\u662f\u7d27\u8ddf\u5728\u5192\u53f7\u540e\u7684\u4e00\u4e2a\u5206\u8bcd\uff0c\u6240\u4ee5\u641c\u7d22\u5b57\u4e32\uff1a<\/P><br \/>\n<P>&nbsp;title:Do it right<\/P><br \/>\n<P>\u53ea\u4f1a\u627e\u5230\u6807\u9898\u542b\u6709 &#8220;Do&#8221; \u7684\u8bb0\u5f55\u3002\u5b83\u4f1a\u5728\u9ed8\u8ba4\u5b57\u6bb5\uff08\u8fd9\u91cc\u662f\u6b63\u6587\u5b57\u6bb5\uff09\u91cc\u67e5\u627e &#8220;it&#8221; \u548c &#8220;right&#8221;\u3002<\/P><br \/>\n<P>\u5206\u8bcd\u4fee\u9970\u8bed<\/P><br \/>\n<P>Lucene\u652f\u6301\u5bf9\u67e5\u8be2\u5206\u8bcd\u505a\u4fee\u9970\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u66f4\u5e7f\u7684\u67e5\u8be2\u9009\u9879\u3002<BR>&nbsp;<BR>\u901a\u914d\u7b26\u641c\u7d22<\/P><br \/>\n<P>ucene\u652f\u6301\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u7684\u901a\u914d\u7b26\u641c\u7d22\u3002<\/P><br \/>\n<P>\u6267\u884c\u4e00\u4e2a\u5b57\u7b26\u7684\u901a\u914d\u7b26\u641c\u7d22\u53ef\u4ee5\u7528 &#8220;?&#8221;\uff0c\u6bd4\u5982\u4f60\u8981\u641c\u7d22 &#8220;text&#8221; or &#8220;test&#8221; \uff0c\u4f60\u53ef\u4ee5\u7528\uff1a<\/P><br \/>\n<P>&nbsp;te?t<\/P><br \/>\n<P>\u6267\u884c\u591a\u4e2a\u5b57\u7b26\u7684\u901a\u914d\u7b26\u641c\u7d22\u53ef\u4ee5\u7528 &#8220;*&#8221;\uff0c\u6bd4\u5982\uff0c\u641c\u7d22 &#8220;test&#8221; \uff0c &#8220;tests&#8221; \u6216 &#8220;tester&#8221; \uff0c\u4f60\u53ef\u4ee5\u7528<\/P><br \/>\n<P>&nbsp;test*<\/P><br \/>\n<P>\u4f60\u4e5f\u53ef\u4ee5\u628a\u901a\u914d\u7b26\u653e\u5728\u5206\u8bcd\u4e2d\u5c06\u8fdb\u884c\u641c\u7d22\uff0c\u6bd4\u5982<\/P><br \/>\n<P>&nbsp;te*t<\/P><br \/>\n<P>\u6ce8\u610f\uff1a\u4e0d\u53ef\u4ee5\u4f7f\u7528 * \u6216 ? \u4f5c\u4e3a\u641c\u7d22\u5b57\u4e32\u7684\u7b2c\u4e00\u4e2a\u652f\u4ed8\u3002<\/P><br \/>\n<P>\u6a21\u7cca\u641c\u7d22<\/P><br \/>\n<P>Lucene\u652f\u6301\u57fa\u4e8eLevenshtein Distance\uff08\u4e00\u79cd\u5b57\u7b26\u4e32\u76f8\u4f3c\u7a0b\u5ea6\u7b97\u6cd5\uff09\u6216Edit Distance\uff08\u4e00\u79cd\u5b57\u7b26\u4e32\u76f8\u4f3c\u7a0b\u5ea6\u7b97\u6cd5\uff09\u7b97\u6cd5\u7684\u6a21\u7cca\u67e5\u8be2\u3002\u8981\u6267\u884c\u6a21\u7cca\u67e5\u8be2\u9700\u8981\u7528\u5230 &#8220;~&#8221; \u7b26\u53f7\uff0c\u7d27\u968f\u5355\u4e2a\u5206\u8bcd\u3002\u6bd4\u5982\uff0c\u7528\u6a21\u7cca\u67e5\u8be2\u641c\u7d22\u4e00\u4e2a\u62fc\u5199\u4e0a\u548c &#8220;roam&#8221; \u7c7b\u4f3c\u7684\u5185\u5bb9\uff1a<\/P><br \/>\n<P>&nbsp;roam~<\/P><br \/>\n<P>\u8fd9\u4e2a\u641c\u7d22\u53ef\u4ee5\u641c\u7d22\u5230\u50cf foam \u548c roams \u8fd9\u6837\u7684\u5206\u8bcd\u3002<\/P><br \/>\n<P>&nbsp;&#8220;jakarta apache&#8221;~10<\/P><br \/>\n<P>&nbsp;\u8fd1\u4f3c\u641c\u7d22<\/P><br \/>\n<P>Lucene\u652f\u6301\u6839\u636e\u4e00\u4e2a\u6307\u5b9a\u7684\u8fd1\u4f3c\u7a0b\u5ea6\u67e5\u627e\u3002\u4e0e\u6a21\u7cca\u641c\u7d22\u7c7b\u4f3c\uff0c\u5728\u77ed\u8bed\u7684\u672b\u5c3e\u4f7f\u7528 &#8220;~&#8221; \u3002<\/P><br \/>\n<P>\u8303\u56f4\u641c\u7d22<\/P><br \/>\n<P>\u8303\u56f4\u641c\u7d22\u53ef\u4ee5\u641c\u7d22\u5230\u90a3\u4e9b\u5217\u7684\u503c\u5728\u88ab\u8303\u56f4\u641c\u7d22\u6240\u6307\u5b9a\u7684\u4e0a\u9650\u548c\u4e0b\u9650\u4e4b\u95f4\u7684\u8bb0\u5f55\u3002\u8303\u56f4\u641c\u7d22\u53ef\u4ee5\u5305\u62ec\u6216\u4e0d\u5305\u62ec\u4e0a\u9650\u548c\u4e0b\u9650\u3002\u5982\u679c\u4e0d\u662f\u65e5\u671f\u7c7b\u578b\u7684\u5b57\u6bb5\uff0c\u4f1a\u6839\u636e\u5b57\u5178\u7684\u6392\u5e8f\u6765\u51b3\u5b9a\u4e0a\u4e0b\u9650\u3002<\/P><br \/>\n<P>&nbsp;mod_date:[20020101 TO 20030101]<\/P><br \/>\n<P>\u8fd9\u4e2a\u4f1a\u641c\u7d22 mod_date \u5b57\u6bb5\u7684\u503c\u5728 20020101 \u548c 20030101 \u4e4b\u95f4\u7684\uff0c\u5305\u62ec\u4e0a\u4e0b\u9650\u3002\u6ce8\u610f\uff0c\u8303\u56f4\u641c\u7d22\u4e0d\u4ec5\u4ec5\u662f\u4e3a\u65e5\u671f\u5b57\u6bb5\u51c6\u5907\u7684\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728\u975e\u65e5\u671f\u7684\u5b57\u6bb5\u4e0a\u4f7f\u7528\u5b83\uff1a<\/P><br \/>\n<P>&nbsp;title:{Aida TO Carmen}<\/P><br \/>\n<P>\u8fd9\u4e2a\u4f1a\u641c\u7d22 title \u5b57\u6bb5\u7684\u503c\u5728 Aida \u548c Carmen \uff08\u6839\u636e\u5b57\u5178\u7684\u987a\u5e8f\uff09 \u7684\u8bb0\u5f55\uff0c\u4e0d\u5305\u62ec Aida \u548c Carmen \u672c\u8eab\u3002<\/P><br \/>\n<P>\u5305\u542b\u7684\u8303\u56f4\u67e5\u8be2\u662f\u7528\u65b9\u62ec\u53f7\u6307\u5b9a\u7684 &#8220;[&#8221; \u3001 &#8220;]&#8221; \uff0c\u800c\u4e0d\u5305\u542b\u7684\u8303\u56f4\u67e5\u8be2\u662f\u6709\u6ce2\u5f62\u62ec\u53f7\u6307\u5b9a\u7684 &#8220;{&#8221; \u3001 &#8220;}&#8221;\u3002<\/P><br \/>\n<P>\u63d0\u9ad8\u4e00\u4e2a\u5206\u8bcd\u7684\u76f8\u4f3c\u5ea6<\/P><br \/>\n<P>Lucene\u63d0\u4f9b\u57fa\u4e8e\u88ab\u641c\u7d22\u7684\u5206\u8bcd\u7684\u5339\u914d\u6587\u6863\u7684\u76f8\u4f3c\u5ea6\u8fd9\u4e00\u6982\u5ff5\u3002\u4e3a\u4e86\u63d0\u9ad8\u4e00\u4e2a\u5206\u8bcd\u7684\u76f8\u4f3c\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528 &#8220;^&#8221;\u548c\u4e00\u4e2a\u76f8\u4f3c\u56e0\u5b50\uff08\u4e00\u4e2a\u6570\u5b57\uff09\u8ddf\u5728\u9700\u8981\u641c\u7d22\u7684\u5206\u8bcd\u540e\u9762\u3002\u8fd9\u4e2a\u5339\u914d\u56e0\u5b50\u8d8a\u9ad8\uff0c\u8fd9\u4e2a\u5206\u8bcd\u6240\u83b7\u5f97\u76f8\u4f3c\u5ea6\u5c31\u8d8a\u9ad8\u3002<\/P><br \/>\n<P>\u63d0\u9ad8\u5339\u914d\u5141\u8bb8\u4f60\u901a\u8fc7\u63d0\u9ad8\u5206\u8bcd\u7684\u76f8\u4f3c\u7a0b\u5ea6\u6765\u63a7\u5236\u4e00\u4e2a\u6587\u6863\u7684\u76f8\u4f3c\u7a0b\u5ea6\u3002\u6bd4\u5982\uff0c\u5982\u679c\u4f60\u5728\u641c\u7d22<\/P><br \/>\n<P>&nbsp;jakarta apache<\/P><br \/>\n<P>\u5e76\u4e14\uff0c\u4f60\u5e0c\u671b &#8220;jakarta&#8221; \u6709\u66f4\u9ad8\u7684\u76f8\u4f3c\u7a0b\u5ea6\uff0c\u5c31\u7528\u8ba9 &#8220;^&#8221; \u548c\u4e00\u4e2a\u5339\u914d\u56e0\u5b50\u7d27\u968f\u5b83\u3002\u4f60\u5c06\u8f93\u5165\uff1a<\/P><br \/>\n<P>&nbsp;jakarta^4 apache<\/P><br \/>\n<P>\u8fd9\u6837\u4f1a\u4f7f\u5305\u542b\u5206\u8bcd jakarta \u7684\u6587\u6863\u6709\u66f4\u9ad8\u7684\u76f8\u4f3c\u5ea6\uff08Lucene\u9ed8\u8ba4\u662f\u6309\u7167\u76f8\u4f3c\u5ea6\u5bf9\u641c\u7d22\u7ed3\u679c\u6392\u5e8f\u7684\uff0c\u6240\u4ee5\u5e26\u6765\u7684\u76f4\u63a5\u5f71\u54cd\u5c31\u662f\u8be5\u641c\u7d22\u7ed3\u679c\u6587\u6863\u6392\u4f4d\u9760\u524d\uff09\u3002\u4f60\u4e5f\u53ef\u4ee5\u5bf9\u77ed\u8bed\u5206\u8bcd\u63d0\u9ad8\u5339\u914d\u5ea6\uff0c\u6bd4\u5982\uff1a<\/P><br \/>\n<P>&nbsp;&#8220;jakarta apache&#8221;^4 &#8220;jakarta lucene&#8221;<\/P><br \/>\n<P>\u9ed8\u8ba4\u7684\u60c5\u51b5\u4e0b\uff0c\u5339\u914d\u56e0\u5b50\u662f1\u3002\u867d\u7136\u5339\u914d\u56e0\u5b50\u5fc5\u987b\u662f\u6b63\u6570\uff0c\u5f53\u5b83\u53ef\u4ee5\u5c0f\u4e8e1 \uff08\u6bd4\u5982 0.2\uff09<\/P><br \/>\n<P>\u5e03\u5c14\u64cd\u4f5c\u7b26<\/P><br \/>\n<P>\u5e03\u5c14\u64cd\u4f5c\u7b26\u5141\u8bb8\u5206\u8bcd\u901a\u8fc7\u903b\u8f91\u64cd\u4f5c\u7b26\u88ab\u7ec4\u5408\u3002Lucene\u652f\u6301 AND, &#8220;+&#8221;, OR, NOT and &#8220;-&#8221; \u4f5c\u4e3a\u5e03\u5c14\u64cd\u4f5c\u7b26\uff08\u6ce8\u610f\uff1a\u5e03\u5c14\u64cd\u4f5c\u7b26\u5fc5\u987b\u5168\u90e8\u5927\u5199\uff09\u3002<\/P><br \/>\n<P>OR<\/P><br \/>\n<P>OR\u64cd\u4f5c\u7b26\u662f\u9ed8\u8ba4\u7684\u8fde\u63a5\u64cd\u4f5c\u3002\u8fd9\u610f\u5473\u7740\u5982\u679c\u6ca1\u6709\u5e03\u5c14\u503c\u5728\u4e24\u4e2a\u5206\u8bcd\u4e4b\u95f4\u7684\u8bdd\uff0cOR\u64cd\u4f5c\u7b26\u5c06\u88ab\u4f7f\u7528\u3002OR\u64cd\u4f5c\u7b26\u8fde\u63a5\u4e24\u4e2a\u5206\u8bcd\uff0c\u5e76\u4e14\u641c\u7d22\u5305\u542b\u4efb\u610f\u4e00\u4e2a\u5206\u8bcd\u7684\u6587\u6863\u3002\u8fd9\u7b49\u4ef7\u4e8e\u4e0e\u96c6\u5408\u6982\u5ff5\u4e2d\u7684\u5e76\u96c6\u3002 &#8220;||&#8221; \u53ef\u4ee5\u66ff\u4ee3 OR\u3002<\/P><br \/>\n<P>\u641c\u7d22\u5305\u542b &#8220;jakarta apache&#8221; \u6216\u8005 \u53ea\u662f &#8220;jakarta&#8221; \u7684\u6587\u6863\u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&#8220;jakarta apache&#8221; jakarta<\/P><br \/>\n<P>\u6216\u8005<\/P><br \/>\n<P>&nbsp;&#8220;jakarta apache&#8221; OR jakarta<\/P><br \/>\n<P>AND<\/P><br \/>\n<P>AND\u64cd\u4f5c\u7b26\u4f1a\u5339\u914d\u90a3\u4e9b\u5305\u542b\u6240\u6709\u5206\u8bcd\u7684\u6587\u6863\u3002\u8fd9\u7b49\u4ef7\u4e0e\u96c6\u5408\u6982\u5ff5\u4e2d\u7684\u4ea4\u96c6\u3002&#8221;&amp;&amp;&#8221; \u53ef\u4ee5\u66ff\u4ee3 AND\u3002<\/P><br \/>\n<P>\u641c\u7d22\u65e2\u5305\u542b &#8220;jakarta apache&#8221; \u53c8\u5305\u542b &#8220;jakarta&#8221; \u7684\u6587\u6863\u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&nbsp;&#8220;jakarta apache&#8221; AND &#8220;jakarta lucene&#8221;<BR>&nbsp; <BR>\uff0b\u4f5c\u4e3a\u5fc5\u9700\u64cd\u4f5c\u7b26\uff0c\u9700\u8981 &#8220;+&#8221; \u540e\u7684\u5206\u8bcd\u5fc5\u987b\u5b58\u5728\u4e8e\u88ab\u641c\u7d22\u6587\u6863\u7684\u67d0\u4e2a\u5b57\u6bb5\u4e2d\u3002<\/P><br \/>\n<P>\u641c\u7d22\u5fc5\u987b\u542b\u6709 &#8220;jakarta&#8221; \u540c\u65f6\u53ef\u80fd\u542b\u6709 &#8220;lucene&#8221; \u7684\u6587\u6863\u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&nbsp;+jakarta apache<\/P><br \/>\n<P>NOT<\/P><br \/>\n<P>NOT\u64cd\u4f5c\u7b26\u4f1a\u6392\u9664\u5305\u542bNOT\u540e\u7684\u5206\u8bcd\u7684\u6587\u6863\u3002\u8fd9\u7b49\u4ef7\u4e8e\u96c6\u5408\u6982\u5ff5\u4e2d\u7684\u8865\u96c6\u3002&#8221;!&#8221; \u53ef\u4ee5\u66ff\u4ee3 NOT\u3002<\/P><br \/>\n<P>\u641c\u7d22\u5305\u542b&#8221;jakarta apache&#8221; \u4f46\u4e0d\u5305\u542b &#8220;jakarta lucene&#8221;\u7684\u6587\u6863\u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&nbsp;&#8220;jakarta apache&#8221; NOT &#8220;jakarta lucene&#8221;<\/P><br \/>\n<P>\u6ce8\u610f\uff1aNOT\u64cd\u4f5c\u7b26\u4e0d\u80fd\u53ea\u548c\u4e00\u4e2a\u5206\u8bcd\u4e00\u8d77\u4f7f\u7528\uff0c\u4e0b\u9762\u8fd9\u4e2a\u67e5\u8be2\u4e0d\u4f1a\u8fd4\u56de\u4efb\u4f55\u7ed3\u679c\uff1a<\/P><br \/>\n<P>&nbsp;NOT &#8220;jakarta apache&#8221;<\/P><br \/>\n<P>&#8220;-&#8220;\u4f5c\u4e3a\u7981\u6b62\u64cd\u4f5c\u7b26\u5c06\u4e0d\u5339\u914d\u5305\u542b&#8221;-&#8220;\u6240\u8ddf\u968f\u7684\u5206\u8bcd\u7684\u6587\u6863\u3002<\/P><br \/>\n<P>\u641c\u7d22\u5305\u542b&#8221;jakarta apache&#8221; \u800c\u4e0d\u5305\u542b &#8220;jakarta lucene&#8221; \u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&nbsp;&#8220;jakarta apache&#8221; -&#8220;jakarta lucene&#8221;<BR>&nbsp;<BR>\u5206\u7ec4<\/P><br \/>\n<P>Lucene\u652f\u4ed8\u4f7f\u7528\u5706\u62ec\u53f7\u628a\u5b50\u53e5\u5206\u7ec4\u5f62\u6210\u5b50\u67e5\u8be2\u3002\u5982\u679c\u4f60\u60f3\u63a7\u5236\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u7684\u5e03\u5c14\u903b\u8f91\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5c06\u975e\u5e38\u6709\u7528\u3002<\/P><br \/>\n<P>\u67e5\u627e\u5305\u542b &#8220;jakarta&#8221; \u6216\u8005 &#8220;apache&#8221; \uff0c \u540c\u65f6\u5305\u542b &#8220;website&#8221; \u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&nbsp;(jakarta OR apache) AND website<\/P><br \/>\n<P>\u8fd9\u4e2a\u5c06\u4f1a\u6392\u9664\u4efb\u4f55\u6df7\u6dc6\uff0c\u5e76\u786e\u5b9a\u88ab\u641c\u7d22\u7684\u6587\u6863\u5fc5\u987b\u5305\u62ec website \u8fd9\u4e2a\u5206\u8bcd\u5e76\u4e14\u5305\u62ec jakarta \u6216\u8005 apache \u4e2d\u7684\u4e00\u4e2a\u3002<BR>&nbsp; <BR>\u5b57\u6bb5\u5206\u7ec4<\/P><br \/>\n<P>Lucene\u652f\u6301\u9488\u5bf9\u5355\u4e00\u5b57\u6bb5\u4f7f\u7528\u5706\u62ec\u53f7\u5bf9\u591a\u4e2a\u5b50\u53e5\u5206\u7ec4\u3002<\/P><br \/>\n<P>\u8981\u641c\u7d22\u4e00\u4e2a\u6807\u9898\u65e2\u5305\u542b\u5206\u8bcd&#8221;return&#8221; \uff0c \u53c8\u5305\u542b\u77ed\u8bed &#8220;pink panther&#8221; \u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>\u7279\u6b8a\u5b57\u7b26\u8f6c\u6362<\/P><br \/>\n<P>\u4f5c\u4e3a\u67e5\u8be2\u8bed\u6cd5\u7684\u4e00\u90e8\u5206\uff0cLucene\u652f\u6301\u7279\u6b8a\u5b57\u7b26\u3002\u5f53\u524d\u7279\u6b8a\u652f\u4ed8\u5305\u62ec\uff1a<\/P><br \/>\n<P>+ &#8211; &amp;&amp; || ! ( ) { } [ ] ^ &#8221; ~ * ? : \\<\/P><br \/>\n<P>\u8981\u8f6c\u5316\u4e00\u4e2a\u7279\u6b8a\u5b57\u7b26\uff0c\u5c31\u5728\u8981\u8f6c\u5316\u7684\u5b57\u7b26\u524d\u52a0\u4e0a &#8220;\\&#8221; \uff0c \u4f8b\u5982\uff0c\u641c\u7d22 (1+1):2 \u4f7f\u7528\u67e5\u8be2\u8bed\u53e5\uff1a<\/P><br \/>\n<P>&nbsp;\\(1\\+1\\)\\:2<\/P><br \/>\n<P>\u539f\u6587\uff1a<A href=\"http:\/\/jakarta.apache.org\/lucene\/docs\/queryparsersyntax.html\">http:\/\/jakarta.apache.org\/lucene\/docs\/queryparsersyntax.html<\/A><BR><\/P><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lucene Query Parser \u7ffb\u8bd1\u8fd9\u7bc7\u6587\u7ae0\u7684\u521d\u8877\u662f\u5e0c\u671b\u80fd\u66f4\u7cfb\u7edf\u7684\u7406\u89e3Lucene\u7684\u7528\u6cd5\uff0c\u540c\u65f6\u8bd5\u8bd5\u81ea\u5df1\u7684\u7ffb\u8bd1\u6c34\u5e73\uff1a\uff09 \u539f\u6587\uff1ahttp:\/\/jakarta.apache.org\/lucene\/docs\/queryparsersyntax.html \u6982\u8ff0 \u867d\u7136Lucene\u63d0\u4f9b\u7684API\u5141\u8bb8\u4f60\u521b\u5efa\u4f60\u81ea\u5df1\u7684Query\uff08\u67e5\u8be2\u8bed\u53e5\uff09\uff0c\u4f46\u5b83\u540c\u65f6\u4e5f\u901a\u8fc7Query Parser\uff08\u67e5\u8be2\u5206\u6790\u5668\uff09\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u67e5\u8be2\u8bed\u8a00\u3002 \u8fd9\u4e2a\u9875\u9762\u63d0\u4f9b\u7684\u662fLucene\u7684Query Parser\u7684\u8bed\u6cd5\u4ecb\u7ecd\uff1a\u4e00\u4e2a\u53ef\u901a\u8fc7\u7528JavaCC\u628a\u4e00\u4e2a\u5b57\u7b26\u4e32\u89e3\u91ca\u6210\u4e3aLucene\u7684\u67e5\u8be2\u8bed\u53e5\u7684\u89c4\u5219\u3002 \u5728\u9009\u62e9\u4f7f\u7528\u88ab\u63d0\u4f9b\u7684Query Parser\u524d\uff0c\u8bf7\u8003\u8651\u4e00\u4e0b\u51e0\u70b9\uff1a 1\u3001\u5982\u679c\u4f60\u662f\u901a\u8fc7\u7f16\u5199\u7a0b\u5e8f\u751f\u6210\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\uff0c\u7136\u540e\u901a\u8fc7Query Parser\u5206\u6790\uff0c\u90a3\u4e48\u4f60\u9700\u8981\u8ba4\u771f\u7684\u8003\u8651\u662f\u5426\u8be5\u76f4\u63a5\u5229\u7528Query\u7684API\u6784\u9020\u4f60\u7684\u67e5\u8be2\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cQuery Parser\u662f\u4e3a\u90a3\u4e9b\u4eba\u5de5\u8f93\u5165\u7684\u6587\u672c\u6240\u8bbe\u8ba1\u7684\uff0c\u800c\u4e0d\u662f\u4e3a\u4e86\u7a0b\u5e8f\u751f\u6210\u7684\u6587\u672c\u3002 2\u3001\u672a\u5206\u8bcd\u7684\u5b57\u6bb5\u6700\u597d\u76f4\u63a5\u52a0\u5230Query\u4e2d\uff0c\u800c\u4e0d\u8981\u901a\u8fc7Query Parser\u3002\u5982\u679c\u4e00\u4e2a\u5b57\u6bb5\u7684\u503c\u662f\u7531\u7a0b\u5e8f\u751f\u6210\u7684\uff0c\u90a3\u4e48\u9700\u8981\u4e3a\u8fd9\u4e2a\u5b57\u6bb5\u751f\u6210\u4e00\u4e2aQuery Clause\uff08\u67e5\u8be2\u5b50\u53e5\uff09\u3002Query Parser\u6240\u7528\u7684Analyzer\u662f\u4e3a\u8f6c\u6362\u4eba\u5de5\u8f93\u5165\u7684\u6587\u672c\u4e3a\u5206\u8bcd\u7684\u3002\u800c\u7a0b\u5e8f\u751f\u6210\u7684\u503c\uff0c\u6bd4\u5982\u65e5\u671f\u3001\u5173\u952e\u5b57\u7b49\uff0c\u4e00\u822c\u90fd\u7531\u7a0b\u5e8f\u76f4\u63a5\u751f\u6210\uff08\uff1f\uff09\u3002 3\u3001\u5728\u4e00\u4e2a\u67e5\u8be2\u8868\u5355\u91cc\uff0c\u901a\u5e38\u662f\u6587\u672c\u7684\u5b57\u6bb5\u5e94\u8be5\u4f7f\u7528Query Parser\u3002\u6240\u6709\u5176\u4ed6\u7684\uff0c\u6bd4\u5982\u65e5\u671f\u8303\u56f4\u3001\u5173\u952e\u5b57\u7b49\u7b49\uff0c\u6700\u597d\u662f\u901a\u8fc7Query API\u76f4\u63a5\u52a0\u5165\u5230Query\u4e2d\u3002\u4e00\u4e2a\u6709\u6709\u9650\u4e2a\u503c\u7684\u5b57\u6bb5\uff0c\u6bd4\u5982\u901a\u8fc7\u4e0b\u62c9\u8868\u5355\u5b9a\u4e49\u7684\u90a3\u4e9b\uff0c\u4e0d\u5e94\u8be5\u88ab\u52a0\u5230\u67e5\u8be2\u5b57\u4e32\u4e2d\uff08\u540e\u9762\u4f1a\u5206\u6790\u5230\uff09\uff0c\u800c\u5e94\u8be5\u88ab\u6dfb\u52a0\u4e3a\u4e00\u4e2aTermQuery\u5b50\u53e5\u3002 \u5206\u8bcd \u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u662f\u6709\u5206\u8bcd\u548c\u64cd\u4f5c\u7b26\u7ec4\u6210\u7684\u3002\u8fd9\u91cc\u6709\u4e24\u79cd\u7c7b\u578b\u7684\uff1a\u5355\u4e2a\u7684\u5206\u8bcd\u548c\u77ed\u8bed\u3002 \u4e00\u4e2a\u5355\u4e00\u5206\u8bcd\u5c31\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5355\u8bcd\uff0c\u6bd4\u5982&#8221;test&#8221;\u6216&#8221;hello&#8221;\u3002 \u4e00\u4e2a\u77ed\u8bed\u5c31\u662f\u4e00\u7ec4\u88ab\u53cc\u5f15\u53f7\u5305\u62ec\u7684\u5355\u8bcd\uff0c\u6bd4\u5982&#8221;hello dolly&#8221;\u3002 \u591a\u4e2a\u5206\u8bcd\u53ef\u4ee5\u7528\u5e03\u5c14\u64cd\u4f5c\u7b26\u7ec4\u5408\u8d77\u6765\u5f62\u6210\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u67e5\u8be2\u8bed\u53e5\uff08\u4e0b\u9762\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\uff09\u3002 \u6ce8\u610f\uff1a\u7528\u4e8e\u5efa\u7acb\u7d22\u5f15\u7684\u5206\u6790\u5668\uff08Analyzer\uff09\u5c06\u88ab\u7528\u4e8e\u89e3\u91ca\u67e5\u8be2\u8bed\u53e5\u4e2d\u7684\u5206\u8bcd\u548c\u77ed\u8bed\u3002\u56e0\u6b64\uff0c\u5408\u7406\u7684\u9009\u62e9\u4e00\u4e2a\u5206\u6790\u5668\u662f\u5f88\u91cd\u8981\u7684\uff0c\u5f53\u7136\u8fd9\u4e0d\u4f1a\u5f71\u54cd\u4f60\u5728\u67e5\u8be2\u8bed\u53e5\u4e2d\u4f7f\u7528\u7684\u5206\u8bcd\u3002 \u5b57\u6bb5 Lucene\u652f\u6301\u5b57\u6bb5\u6570\u636e\u3002\u5f53\u6267\u884c\u4e00\u4e2a\u641c\u7d22\u65f6\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6216\u8005\u4f7f\u7528\u9ed8\u8ba4\u7684\u5b57\u6bb5\u3002\u5b57\u6bb5\u7684\u540d\u5b57\u548c\u9ed8\u8ba4\u7684\u5b57\u6bb5\u662f\u53d6\u51b3\u4e8e\u5b9e\u73b0\u7ec6\u8282\u7684\u3002 \u4f60\u53ef\u4ee5\u641c\u7d22\u4efb\u4f55\u5b57\u6bb5\uff0c\u505a\u6cd5\u662f\u8f93\u5165\u5b57\u6bb5\u540d\u79f0\uff0c\u7ed3\u5c3e\u8ddf\u4e0a\u4e00\u4e2a\u5192\u53f7 &#8220;:&#8221; \uff0c \u7136\u540e\u8f93\u5165\u4f60\u60f3\u67e5\u627e\u7684\u5206\u8bcd\u3002 \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u8ba9\u6211\u4eec\u5047\u8bbeLucene\u7684\u7d22\u5f15\u5305\u542b\u4e24\u4e2a\u5b57\u6bb5\uff0c\u6807\u9898\u548c\u6b63\u6587\uff0c\u6b63\u6587\u662f\u9ed8\u8ba4\u5b57\u6bb5\u3002\u5982\u679c\u4f60\u60f3\u6807\u9898\u4e3a &#8220;The Right Way&#8221; \u5e76\u4e14\u6b63\u6587\u5305\u542b\u6587\u672c &#8220;don&#8217;t go this way&#8221;\u7684\u8bb0\u5f55\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\uff1a &nbsp; title:&#8221;The Right Way&#8221; AND text:go&nbsp; \u6216\u8005 &nbsp; title:&#8221;Do it right&#8221; &hellip; <a href=\"https:\/\/www.strongd.net\/?p=521\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Lucene Query Parser<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6,11],"tags":[75],"class_list":["post-521","post","type-post","status-publish","format-standard","hentry","category-java","category-linux","category-11","tag-lucene"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=521"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/521\/revisions"}],"predecessor-version":[{"id":851,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/521\/revisions\/851"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}