@Override public Map<Integer, LocalPage> getCategories(Language language, int articleId) throws DaoException { Collection<Integer> categoryIds = getCategoryIds(language, articleId); return localPageDao.getByIds(language, categoryIds); }
@Override public Map<Integer, LocalPage> getCategoryMembers(Language language, int categoryId) throws DaoException { Collection<Integer> articleIds = getCategoryMemberIds(language, categoryId); return localPageDao.getByIds(language, articleIds); }
@Override public Map<LocalPage, TIntDoubleMap> getClosestCategories(Set<LocalPage> topLevelCats) throws DaoException { return getClosestCategories(topLevelCats, null, true); }
@Override public Collection<Integer> getCategoryMemberIds(Language language, int categoryId) throws DaoException { DSLContext context = getJooq(); try { Result<Record> result = context.select(). from(Tables.CATEGORY_MEMBERS). where(Tables.CATEGORY_MEMBERS.CATEGORY_ID.eq(categoryId)). and(Tables.CATEGORY_MEMBERS.LANG_ID.eq(language.getId())). fetch(); return extractIds(result, false); } finally { freeJooq(context); } }
/** * This method should generally not be used. * @param daoFilter a set of filters to limit the search * @return * @throws DaoException */ @Override public Iterable<LocalCategoryMember> get(DaoFilter daoFilter) throws DaoException { DSLContext context = getJooq(); try { Collection<Condition> conditions = new ArrayList<Condition>(); if (daoFilter.getLangIds() != null) { conditions.add(Tables.CATEGORY_MEMBERS.LANG_ID.in(daoFilter.getLangIds())); } Cursor<Record> result = context.select(). from(Tables.CATEGORY_MEMBERS). where(conditions). limit(daoFilter.getLimitOrInfinity()). fetchLazy(getFetchSize()); return new SimpleSqlDaoIterable<LocalCategoryMember>(result, context) { @Override public LocalCategoryMember transform(Record r) { return buildLocalCategoryMember(r); } }; } catch (RuntimeException e) { freeJooq(context); throw e; } }
univDao = getConfigurator().get(UniversalPageDao.class); LocalCategoryMemberSqlDao dao = new LocalCategoryMemberSqlDao( getConfigurator().get( WpDataSource.class, Config c = config.getConfig("topLevelCats"); for (Map.Entry<String, ConfigValue> e : c.entrySet()) { dao.addTopLevelOverride(Language.getByLangCode(e.getKey()), (String) e.getValue().unwrapped()); cacheDir.mkdirs(); dao.useCache(cacheDir); return dao; } catch (DaoException e) {
@Override public int getCount(DaoFilter daoFilter) throws DaoException{ DSLContext context = getJooq(); try { Collection<Condition> conditions = new ArrayList<Condition>(); if (daoFilter.getLangIds() != null) { conditions.add(Tables.CATEGORY_MEMBERS.LANG_ID.in(daoFilter.getLangIds())); } return context.selectCount(). from(Tables.CATEGORY_MEMBERS). where(conditions). fetchOne().value1(); } finally { freeJooq(context); } }
CategoryGraph graph = getGraph(language); for (int catId : getCategoryIds(language, pageId)) { int i = graph.catIdToIndex(catId); if (i >= 0) frontier.add(new CatCost(null, -1, i, graph.catCosts[i]));
@Override public LocalPage getClosestCategory(LocalPage page, Set<LocalPage> candidates, boolean weightedDistance) throws DaoException { CategoryGraph graph = getGraph(page.getLanguage()); CategoryBfs bfs = new CategoryBfs(graph, page.getLocalId(), page.getLanguage(), Integer.MAX_VALUE, null, this); bfs.setAddPages(false); bfs.setExploreChildren(false); Map<Integer, LocalPage> indexToCandidates = new HashMap<Integer, LocalPage>(); for (LocalPage c : candidates) { indexToCandidates.put(graph.catIdToIndex(c.getLocalId()), c); } List<LocalPage> matches = new ArrayList<LocalPage>(); while (bfs.hasMoreResults() && matches.isEmpty()) { CategoryBfs.BfsVisited visited = bfs.step(); for (int catId : visited.cats.keys()) { if (indexToCandidates.containsKey(catId)) { matches.add(indexToCandidates.get(catId)); } } } if (matches.isEmpty()) { return null; } else { return matches.get(new Random().nextInt(matches.size())); } }
@Override public Collection<Integer> getCategoryIds(Language language, int articleId) throws DaoException { DSLContext context = getJooq(); try { Result<Record> result = context.select(). from(Tables.CATEGORY_MEMBERS). where(Tables.CATEGORY_MEMBERS.ARTICLE_ID.eq(articleId)). and(Tables.CATEGORY_MEMBERS.LANG_ID.eq(language.getId())). fetch(); return extractIds(result, true); } finally { freeJooq(context); } }
CategoryGraph graph = getGraph(language); int numPages = (pageIds == null) ? LanguageInfo.getByLanguage(language).getNumArticles() : pageIds.size();
@Override public Map<Integer, LocalPage> getCategoryMembers(LocalPage localCategory) throws DaoException { Collection<Integer> articleIds = getCategoryMemberIds(localCategory); return localPageDao.getByIds(localCategory.getLanguage(), articleIds); }
@Override public Map<Integer, LocalPage> getCategories(LocalPage localArticle) throws DaoException { Collection<Integer> categoryIds = getCategoryIds(localArticle); return localPageDao.getByIds(localArticle.getLanguage(), categoryIds); }
@Override public Collection<Integer> getCategoryMemberIds(LocalPage localCategory) throws DaoException { return getCategoryMemberIds(localCategory.getLanguage(), localCategory.getLocalId()); }
@Override public Collection<Integer> getCategoryIds(LocalPage localArticle) throws DaoException { return getCategoryIds(localArticle.getLanguage(), localArticle.getLocalId()); }
@Override public Set<LocalPage> guessTopLevelCategories(Language language) throws DaoException { int topLevelId = -1; Title override = topLevelLangOverrides.get(language); if (override != null) { System.out.println("title is " + override); topLevelId = localPageDao.getIdByTitle(override); if (topLevelId < 0) { LOG.warn("top level category {} for language {} not found.", override, language); } } if (topLevelId < 0) { if (univDao == null) { throw new DaoException("Universal dao required for top level categories."); } topLevelId = univDao.getLocalId(language, TOP_LEVEL_CONCEPT); } Set<LocalPage> result = new HashSet<LocalPage>(); if (topLevelId < 0) { return result; } for (int id : getCategoryMemberIds(language, topLevelId)) { LocalPage page = localPageDao.getById(language, id); if (page.getNameSpace() == NameSpace.CATEGORY) { result.add(page); } } return result; }