{"id":3532,"date":"2018-12-12T11:22:16","date_gmt":"2018-12-12T03:22:16","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3532"},"modified":"2018-12-12T11:22:16","modified_gmt":"2018-12-12T03:22:16","slug":"lucene-%e5%ae%9e%e6%88%98%e6%95%99%e7%a8%8b%e7%ac%ac%e5%85%ad%e7%ab%a0-lucene-%e7%9a%84%e7%b2%be%e7%a1%ae%e3%80%81%e5%8c%85%e5%90%ab%e3%80%81%e9%9b%86%e5%90%88%e6%9f%a5%e8%af%a2-query-%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3532","title":{"rendered":"Lucene \u5b9e\u6218\u6559\u7a0b\u7b2c\u516d\u7ae0 Lucene \u7684\u7cbe\u786e\u3001\u5305\u542b\u3001\u96c6\u5408\u67e5\u8be2 Query \u7684\u7b80\u5355\u4f7f\u7528"},"content":{"rendered":"<p>\n\t\u6240\u6709\u7684\u641c\u7d22\u57fa\u672c\u4e0a\u90fd\u5b58\u5728\u7cbe\u786e\u5339\u914d\uff0c\u5305\u542b\u7b49\u64cd\u4f5c\u3002Lucene \u4e2d\u540c\u6837\u5b58\u5728\u8fd9\u6837\u7684\u64cd\u4f5c\uff0c\u4eca\u5929\u6211\u4eec\u4ee5 IntPoint \u4e3a\u4f8b\uff0c\u6765\u8bf4\u8bf4 Lucene \u4e2d\u7684\u7cbe\u786e\u67e5\u8be2\u3002\n<\/p>\n<p>\n\tIntPoint\u3001LongPoint\u3001FloatPoint\u3001DoublePoint \u8fd9\u4e2a 4 \u4e2a\u7684\u64cd\u4f5c\u7c7b\u4f3c\uff0c\u6211\u5c31\u53ea\u4ee5 IntPoint \u6765\u8fdb\u884c\u4e3e\u4f8b\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\n@Test\r\npublic void testIntPointQuery() throws IOException {\r\n    Directory directory = new RAMDirectory();\r\n    IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(new StandardAnalyzer()));\r\n\r\n    \/\/ \u521b\u5efa Document\r\n    Document document = new Document();\r\n\r\n    \/\/ \u521b\u5efa Field \u5b57\u6bb5\/\u57df\r\n    Field intPoint = new IntPoint(&quot;age&quot;, 11);\r\n    document.add(intPoint);\r\n    intPoint = new StoredField(&quot;age&quot;, 11);\r\n    document.add(intPoint);\r\n    indexWriter.addDocument(document);\r\n\r\n    Field intPoint1 = new IntPoint(&quot;age&quot;, 22);\r\n    document = new Document();\r\n    document.add(intPoint1);\r\n    intPoint1 = new StoredField(&quot;age&quot;, 22);\r\n    document.add(intPoint1);\r\n    \r\n    indexWriter.addDocument(document);\r\n    indexWriter.close();\r\n    IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(directory));\r\n    \/\/\u7cbe\u786e\u67e5\u8be2\r\n    Query query = IntPoint.newExactQuery(&quot;age&quot;, 11);\r\n    ScoreDoc[] scoreDocs = indexSearcher.search(query, 10).scoreDocs;\r\n    for (ScoreDoc scoreDoc : scoreDocs) {\r\n        System.out.println(&quot;\u7cbe\u786e\u67e5\u8be2\uff1a&quot; + indexSearcher.doc(scoreDoc.doc));\r\n    }\r\n    \/\/\u8303\u56f4\u67e5\u8be2\uff0c\u4e0d\u5305\u542b\u8fb9\u754c\r\n    query = IntPoint.newRangeQuery(&quot;age&quot;, Math.addExact(11, 1), Math.addExact(22, -1));\r\n    scoreDocs = indexSearcher.search(query, 10).scoreDocs;\r\n    for (ScoreDoc scoreDoc : scoreDocs) {\r\n        System.out.println(&quot;\u4e0d\u5305\u542b\u8fb9\u754c\uff1a&quot; + indexSearcher.doc(scoreDoc.doc));\r\n    }\r\n    \/\/\u8303\u56f4\u67e5\u8be2\uff0c\u5305\u542b\u8fb9\u754c\r\n    query = IntPoint.newRangeQuery(&quot;age&quot;, 11, 22);\r\n    scoreDocs = indexSearcher.search(query, 10).scoreDocs;\r\n    for (ScoreDoc scoreDoc : scoreDocs) {\r\n        System.out.println(&quot;\u5305\u542b\u8fb9\u754c\uff1a&quot; + indexSearcher.doc(scoreDoc.doc));\r\n    }\r\n    \/\/\u8303\u56f4\u67e5\u8be2\uff0c\u5de6\u5305\u542b\uff0c\u53f3\u4e0d\u5305\u542b\r\n    query = IntPoint.newRangeQuery(&quot;age&quot;, 11, Math.addExact(22, -1));\r\n    scoreDocs = indexSearcher.search(query, 10).scoreDocs;\r\n    for (ScoreDoc scoreDoc : scoreDocs) {\r\n        System.out.println(&quot;\u5de6\u5305\u542b\u53f3\u4e0d\u5305\u542b\uff1a&quot; + indexSearcher.doc(scoreDoc.doc));\r\n    }\r\n    \/\/\u96c6\u5408\u67e5\u8be2\r\n    query = IntPoint.newSetQuery(&quot;age&quot;, 11, 22, 33);\r\n    scoreDocs = indexSearcher.search(query, 10).scoreDocs;\r\n    for (ScoreDoc scoreDoc : scoreDocs) {\r\n        System.out.println(&quot;\u96c6\u5408\u67e5\u8be2\uff1a&quot; + indexSearcher.doc(scoreDoc.doc));\r\n    }\r\n}<\/pre>\n<p>\n\tIntPoint.newExactQuery \u7cbe\u786e\u67e5\u8be2\uff0c\u4f7f\u7528\u7684\u662f PointRangeQuery\u3002<br \/>\n\tIntPoint.newRangeQuery \u8303\u56f4\u67e5\u8be2\uff0c\u4f7f\u7528\u7684\u662f PointRangeQuery\u3002<br \/>\n\tIntPoint.newSetQuery \u96c6\u5408\u67e5\u8be2\uff0c\u4f7f\u7528\u7684\u662f PointInSetQuery\u3002\n<\/p>\n<p>\n\t\u5b83\u4eec\u90fd\u7ee7\u627f\u81ea Query\uff0c\u901a\u8fc7 IntPoint \u53bb\u521b\u5efa\u8fd9\u4e9b\u62bd\u8c61\u7c7b\u7684\u533f\u540d\u5b9e\u73b0\u7c7b\u3002\n<\/p>\n<p>\n\tLongPoint\u3001FloatPoint\u3001DoublePoint \u5c01\u88c5\u7684\u548c IntPoint \u90fd\u5f88\u76f8\u4f3c\uff0c\u6211\u5c31\u4e0d\u5728\u5217\u4e3e\u4e86\u3002\u5927\u5bb6\u4e3b\u8981\u8bb0\u4f4f newExactQuery\uff0cnewRangeQuery\uff0cnewSetQuery \u4e09\u4e2a\u65b9\u6cd5\u7684\u7528\u6cd5\u5373\u53ef\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3532\">Lucene \u5b9e\u6218\u6559\u7a0b\u7b2c\u516d\u7ae0 Lucene \u7684\u7cbe\u786e\u3001\u5305\u542b\u3001\u96c6\u5408\u67e5\u8be2 Query \u7684\u7b80\u5355\u4f7f\u7528<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6240\u6709\u7684\u641c\u7d22\u57fa\u672c\u4e0a\u90fd\u5b58\u5728\u7cbe\u786e\u5339\u914d\uff0c\u5305\u542b\u7b49\u64cd\u4f5c\u3002Lucene \u4e2d\u540c\u6837\u5b58\u5728\u8fd9\u6837\u7684\u64cd\u4f5c\uff0c\u4eca\u5929\u6211\u4eec\u4ee5 IntPoint  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1802,1803,1805,1804,1444],"class_list":["post-3532","post","type-post","status-publish","format-standard","hentry","category-java","tag-doublepoint","tag-floatpoint","tag-intpoint","tag-longpoint","tag-lucene"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3532"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3532\/revisions"}],"predecessor-version":[{"id":3535,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3532\/revisions\/3535"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}