public BrowseFacet getFacet(String value) { int sum = -1; String foundValue = null; if (_list != null) { for (FacetAccessible facetAccessor : _list) { BrowseFacet facet = facetAccessor.getFacet(value); if (facet != null) { foundValue = facet.getValue(); if (sum == -1) sum = facet.getHitCount(); else sum += facet.getHitCount(); } } } if (sum == -1) return null; return new BrowseFacet(foundValue, sum); }
/* * [00000001371(3156), 00000001025(2951), 00000001035(2688), 00000001009(2429), 00000157234(2318), 00000001028(1871), * 00000001063(1711), 00000002114(1371), 00000001033(1340), 00000001384(1187), 00000001292(1016), 00000001694(993), * 00000001483(980), 00000001062(884), 00000001115(883), 00000001441(854), 00000001052(695), 00000001093(681), * 00000001714(665), 00000001128(641), 00000224605(619), 00000001053(616), 00000002271(613), 00000001288(609), * 00000001038(607), 00000001060(585), 00000001043(573), 00000157240(555), 00000001044(549), 00000001663(546), * 00000001231(544), 00000001123(526), 00000001505(497), 00000001120(487), 00000001070(484), 00000001217(480), * 00000001073(478), 00000001006(452), 00000001068(437), 00000001207(432), 00000001066(415), 00000001116(415), * 00000001271(415), 00000001015(407), 00000011448(401), 00000001040(399), 00000001235(393), 00000001058(391), * 00000001482(382), -00000000001(0)] */ private static long oneRun(BoboIndexReader boboReader, Collection<FacetHandler<?>> facetHandlers) throws IOException, BrowseException { long tt = 0; long hitscount = 0; for (int x = 0; x < inNumItr; x++) { long t0 = System.currentTimeMillis(); BoboBrowser browser = new BoboBrowser(boboReader); BrowseRequest req = new BrowseRequest(); req.setCount(500); FacetSpec spec = new FacetSpec(); spec.setMaxCount(50); spec.setOrderBy(FacetSortSpec.OrderHitsDesc); // req.setFacetSpec("ccid", spec); // req.setFacetSpec("pcid", spec); // req.setFacetSpec("education_id", spec); req.setFacetSpec("geo_region", spec); // req.setFacetSpec("industry", spec); String qstr = words[nextInt()]; // qstr = "project manager"; String[] terms = qstr.split(" "); BooleanQuery q = new BooleanQuery(); for (String s : terms) { q.add(new TermQuery(new Term("b", s)), Occur.MUST); } // q.add(new MatchAllDocsQuery(), Occur.MUST); req.setQuery(q); // new TermQuery(new Term("b",qstr))); BrowseSelection sel = new BrowseSelection("ccid"); sel.addValue("0000001384"); // req.addSelection(sel ); BrowseSelection seli = new BrowseSelection("industry"); seli.addValue("0000000052"); // req.addSelection(seli ); long tf0 = 0; long tf1 = 0; BrowseResult bres = browser.browse(req); for (Entry<String, FacetAccessible> entry : bres.getFacetMap().entrySet()) { // System.out.println(entry.getKey()); FacetAccessible fa = entry.getValue(); tf0 = System.currentTimeMillis(); List<BrowseFacet> facets = fa.getFacets(); tf1 = System.currentTimeMillis(); System.out.println( tf1 - tf0 + "\tfacet " + entry.getKey() + " get time\tsize: " + facets.size()); // System.out.println(Arrays.toString(facets.toArray())); fa.close(); } browser.close(); // System.out.println(t2 - t0 +"\ttotal time\t\t\t hits: "+ bres.getNumHits()); hitscount += bres.getNumHits(); long t2 = System.currentTimeMillis(); tt += (t2 - t0); browser.close(); // System.out.println(t2 - t0 -(tf1-tf0)+"\tsearch time\t"); } if (hitscount > 80000) System.out.println("avg hits count: " + hitscount / inNumItr); try { Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tt; }
public List<BrowseFacet> getFacets() { Map<String, BrowseFacet> facetMap; if (FacetSortSpec.OrderValueAsc.equals(_fspec.getOrderBy())) { facetMap = new TreeMap<String, BrowseFacet>(); } else { facetMap = new HashMap<String, BrowseFacet>(); } for (FacetAccessible facetAccessor : _list) { Iterator<BrowseFacet> iter = facetAccessor.getFacets().iterator(); if (facetMap.size() == 0) { while (iter.hasNext()) { BrowseFacet facet = iter.next(); facetMap.put(facet.getValue(), facet); } } else { while (iter.hasNext()) { BrowseFacet facet = iter.next(); BrowseFacet existing = facetMap.get(facet.getValue()); if (existing == null) { facetMap.put(facet.getValue(), facet); } else { existing.setHitCount(existing.getHitCount() + facet.getHitCount()); } } } } int cnt = 0; int maxCnt = _fspec.getMaxCount(); if (maxCnt <= 0) maxCnt = Integer.MAX_VALUE; int minHits = _fspec.getMinHitCount(); List<BrowseFacet> list = new LinkedList<BrowseFacet>(); if (FacetSortSpec.OrderValueAsc.equals(_fspec.getOrderBy())) { for (BrowseFacet facet : facetMap.values()) { if (facet.getHitCount() >= minHits) { list.add(facet); if (++cnt >= maxCnt) break; } } } else { Comparator<BrowseFacet> comparator; if (FacetSortSpec.OrderHitsDesc.equals(_fspec.getOrderBy())) { comparator = new Comparator<BrowseFacet>() { public int compare(BrowseFacet f1, BrowseFacet f2) { int val = f2.getHitCount() - f1.getHitCount(); if (val == 0) { val = (f1.getValue().compareTo(f2.getValue())); } return val; } }; } else // FacetSortSpec.OrderByCustom.equals(_fspec.getOrderBy() { comparator = _fspec.getCustomComparatorFactory().newComparator(); } ArrayList<BrowseFacet> facets = new ArrayList<BrowseFacet>(facetMap.values()); Collections.sort(facets, comparator); for (BrowseFacet facet : facets) { if (facet.getHitCount() >= minHits) { list.add(facet); if (++cnt >= maxCnt) break; } } } return list; }