日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lucene源码分析(3)facet实例

發布時間:2025/4/5 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lucene源码分析(3)facet实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡單的facet實例

public class SimpleFacetsExample {private final Directory indexDir = new RAMDirectory();private final Directory taxoDir = new RAMDirectory();private final FacetsConfig config = new FacetsConfig();/** Empty constructor */public SimpleFacetsExample() {config.setHierarchical("Publish Date", true);}/** Build the example index. */private void index() throws IOException {IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE));// Writes facet ords to a separate directory from the main indexDirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);Document doc = new Document();doc.add(new FacetField("Author", "Bob"));doc.add(new FacetField("Publish Date", "2010", "10", "15"));indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2010", "10", "20"));indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Lisa"));doc.add(new FacetField("Publish Date", "2012", "1", "1"));indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Susan"));doc.add(new FacetField("Publish Date", "2012", "1", "7"));indexWriter.addDocument(config.build(taxoWriter, doc));doc = new Document();doc.add(new FacetField("Author", "Frank"));doc.add(new FacetField("Publish Date", "1999", "5", "5"));indexWriter.addDocument(config.build(taxoWriter, doc));indexWriter.close();taxoWriter.close();}/** User runs a query and counts facets. */private List<FacetResult> facetsWithSearch() throws IOException {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);FacetsCollector fc = new FacetsCollector();// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);// Retrieve resultsList<FacetResult> results = new ArrayList<>();// Count both "Publish Date" and "Author" dimensionsFacets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);results.add(facets.getTopChildren(10, "Author"));results.add(facets.getTopChildren(10, "Publish Date"));indexReader.close();taxoReader.close();return results;}/** User runs a query and counts facets only without collecting the matching documents.*/private List<FacetResult> facetsOnly() throws IOException {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);FacetsCollector fc = new FacetsCollector();// MatchAllDocsQuery is for "browsing" (counts facets// for all non-deleted docs in the index); normally// you'd use a "normal" query:searcher.search(new MatchAllDocsQuery(), fc);// Retrieve resultsList<FacetResult> results = new ArrayList<>();// Count both "Publish Date" and "Author" dimensionsFacets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);results.add(facets.getTopChildren(10, "Author"));results.add(facets.getTopChildren(10, "Publish Date"));indexReader.close();taxoReader.close();return results;}/** User drills down on 'Publish Date/2010', and we* return facets for 'Author' */private FacetResult drillDown() throws IOException {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);// Passing no baseQuery means we drill down on all// documents ("browse only"):DrillDownQuery q = new DrillDownQuery(config);// Now user drills down on Publish Date/2010:q.add("Publish Date", "2010");FacetsCollector fc = new FacetsCollector();FacetsCollector.search(searcher, q, 10, fc);// Retrieve resultsFacets facets = new FastTaxonomyFacetCounts(taxoReader, config, fc);FacetResult result = facets.getTopChildren(10, "Author");indexReader.close();taxoReader.close();return result;}/** User drills down on 'Publish Date/2010', and we* return facets for both 'Publish Date' and 'Author',* using DrillSideways. */private List<FacetResult> drillSideways() throws IOException {DirectoryReader indexReader = DirectoryReader.open(indexDir);IndexSearcher searcher = new IndexSearcher(indexReader);TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);// Passing no baseQuery means we drill down on all// documents ("browse only"):DrillDownQuery q = new DrillDownQuery(config);// Now user drills down on Publish Date/2010:q.add("Publish Date", "2010");DrillSideways ds = new DrillSideways(searcher, config, taxoReader);DrillSidewaysResult result = ds.search(q, 10);// Retrieve resultsList<FacetResult> facets = result.facets.getAllDims(10);indexReader.close();taxoReader.close();return facets;}/** Runs the search example. */public List<FacetResult> runFacetOnly() throws IOException {index();return facetsOnly();}/** Runs the search example. */public List<FacetResult> runSearch() throws IOException {index();return facetsWithSearch();}/** Runs the drill-down example. */public FacetResult runDrillDown() throws IOException {index();return drillDown();}/** Runs the drill-sideways example. */public List<FacetResult> runDrillSideways() throws IOException {index();return drillSideways();}/** Runs the search and drill-down examples and prints the results. */public static void main(String[] args) throws Exception {System.out.println("Facet counting example:");System.out.println("-----------------------");SimpleFacetsExample example = new SimpleFacetsExample();List<FacetResult> results1 = example.runFacetOnly();System.out.println("Author: " + results1.get(0));System.out.println("Publish Date: " + results1.get(1));System.out.println("Facet counting example (combined facets and search):");System.out.println("-----------------------");List<FacetResult> results = example.runSearch();System.out.println("Author: " + results.get(0));System.out.println("Publish Date: " + results.get(1));System.out.println("Facet drill-down example (Publish Date/2010):");System.out.println("---------------------------------------------");System.out.println("Author: " + example.runDrillDown());System.out.println("Facet drill-sideways example (Publish Date/2010):");System.out.println("---------------------------------------------");for(FacetResult result : example.runDrillSideways()) {System.out.println(result);}}}

查詢及其關系

查詢

/** Lower-level search API.** <p>{@link LeafCollector#collect(int)} is called for every matching document.** @throws BooleanQuery.TooManyClauses If a query would exceed * {@link BooleanQuery#getMaxClauseCount()} clauses.*/public void search(Query query, Collector results)throws IOException {query = rewrite(query); search(leafContexts, createWeight(query, results.needsScores(), 1), results); }

關系

?

轉載于:https://www.cnblogs.com/davidwang456/p/9952368.html

總結

以上是生活随笔為你收集整理的lucene源码分析(3)facet实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 性色av免费观看 | 中文字幕国产一区 | 国产精品探花一区二区在线观看 | 欧美人与动牲交xxxxbbbb | 黄色特级网站 | 午夜免费av | 婷婷五月色综合 | 成人动漫中文字幕 | 日韩av一卡 | 亚洲欧美中文字幕 | 亚洲人人爱 | 三年中国片在线高清观看 | av色站 | h视频在线免费观看 | 性精品 | 黄色骚视频 | 波多野结衣一区二区三区四区 | 国产欧美一区二区三区国产幕精品 | av在线不卡一区 | 综合欧美亚洲 | 日韩一区二区三区网站 | 激情总合网 | 久久婷婷影视 | 五月天色综合 | 美景之屋电影免费高清完整韩剧 | 无码少妇精品一区二区免费动态 | 69av视频在线| 欧美亚洲第一页 | 波多野结衣办公室33分钟 | 色呦呦 | 天天干天天操天天干 | 日本全黄裸体片 | 双性受孕h堵精大肚生子 | 奇米四色在线视频 | 东凛在线观看 | 中文免费视频 | 丁香五香天堂 | 一区二区三区四区不卡 | 91涩涩涩| 免费毛片网站在线观看 | 蜜臀精品一区二区三区 | 国产一区二区三区精品在线观看 | 宅男噜噜噜666在线观看 | 成人av一区 | www.狠狠艹 | www,xxx日本 | 亚洲天堂视频网 | 视频二区在线 | 亚洲国产精品人人爽夜夜爽 | 麻豆国产尤物av尤物在线观看 | a毛片毛片av永久免费 | 亚洲国产日韩在线一区 | 天天色天天操天天 | h在线播放| 超碰人人99 | 超碰在 | av一区二区免费 | 成了校长的性脔h文 | 亚洲欧洲日本国产 | 久久福利视频网 | 欧洲在线视频 | 欧美成人小视频 | 麻豆国产精品777777在线 | 一进一出好爽视频 | 欧美亚洲国产精品 | 亚洲乱子伦 | 亚洲狠狠丁香婷婷综合久久久 | 丰满少妇乱子伦精品看片 | 91爱爱网站| 91传媒理伦片在线观看 | 美女靠逼app| 中文字幕一区二区三区四区视频 | 黄色在线视频播放 | 日本肉体xxxx裸体xxx免费 | 日本一级网站 | 欧美aⅴ视频 | jizzjizz视频| 国产精品一区一区三区 | 香蕉一区二区三区四区 | 日韩亚洲在线 | 国产丝袜美腿一区二区三区 | 国产aⅴ无码片毛片一级一区2 | 日本一区不卡 | 精品久久久久成人码免费动漫 | 久久蜜桃av | 免费福利视频网站 | 日韩av在线播放观看 | 夜色伊人| 日本在线加勒比 | 国产原创在线视频 | 三大队在线观看 | 五月婷婷中文字幕 | 香蕉在线观看视频 | 男生把女生困困的视频 | 一区二区三区高清在线观看 | 在线激情av| 亚洲AV综合色区国产精品天天 | 成人精品一区二区三区电影 | 日韩一二三区在线观看 |