From: <ssk...@vh...> - 2005-11-30 13:28:19
|
Author: sskracic Date: 2005-11-30 14:26:18 +0100 (Wed, 30 Nov 2005) New Revision: 1018 Modified: trunk/ccm-core/pdl/com/arsdigita/search/Search.pdl trunk/ccm-core/src/com/arsdigita/search/intermedia/BaseQueryEngine.java Log: Added support for "descend" option in category filter. Modified: trunk/ccm-core/pdl/com/arsdigita/search/Search.pdl =================================================================== --- trunk/ccm-core/pdl/com/arsdigita/search/Search.pdl 2005-11-30 13:21:46 UTC (rev 1017) +++ trunk/ccm-core/pdl/com/arsdigita/search/Search.pdl 2005-11-30 13:26:18 UTC (rev 1018) @@ -32,3 +32,18 @@ id = m.object_id; } } + +query categoryObjectsDescend { + BigDecimal id; + + do { + select m.object_id + from cat_object_category_map m, + cat_cat_subcat_trans_index cc + where + m.category_id = cc.subcategory_id + and cc.category_id in :ids + } map { + id = m.object_id; + } +} Modified: trunk/ccm-core/src/com/arsdigita/search/intermedia/BaseQueryEngine.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/search/intermedia/BaseQueryEngine.java 2005-11-30 13:21:46 UTC (rev 1017) +++ trunk/ccm-core/src/com/arsdigita/search/intermedia/BaseQueryEngine.java 2005-11-30 13:26:18 UTC (rev 1018) @@ -59,13 +59,13 @@ /** * This provides the basic intermedia query engine implementation - * which can restrict based on category, object type and + * which can restrict based on category, object type and * permissions * @see com.arsdigita.search.QueryEngine */ public class BaseQueryEngine extends LockableImpl implements QueryEngine { - private static final Logger s_log = + private static final Logger s_log = Logger.getLogger(BaseQueryEngine.class); public static final String OBJECT_ID= "object_id"; @@ -91,7 +91,7 @@ addColumn("c.link_text", LINK_TEXT); addColumn("c.summary", SUMMARY); addColumn("c.language", LANGUAGE); - addColumn("c.content_section", CONTENT_SECTION); + addColumn("c.content_section", CONTENT_SECTION); // XML content is labeled as "1" and raw content is labeled as "2" // in buildQueryString(). Those labels must match the arguments // to the "score()" operator used here. @@ -113,7 +113,7 @@ } String terms = cleanSearchString(spec.getTerms()); - + if (terms == null || "".equals(terms)) { return Search.EMPTY_RESULT_SET; } @@ -121,19 +121,19 @@ DataQuery q = buildQuery(terms, spec.allowPartialMatch()); addFilters(q, spec.getFilters()); - - - + + + return new DataQueryResultSet(q); } - + protected DataQuery buildQuery(String terms, boolean partial) { List props = new ArrayList(); String query = buildQueryString(terms, partial, props); - + if (s_log.isDebugEnabled()) { s_log.debug("Query before adding any filters {\n" + query + "}"); } @@ -141,7 +141,7 @@ Session session = SessionManager.getSession(); SearchDataQuery q = new SearchDataQuery( - session, + session, query, (String[])props.toArray(new String[props.size()])); return q; @@ -151,7 +151,7 @@ boolean partial, List props) { StringBuffer sb = new StringBuffer("select \n"); - + Iterator columns = m_columns.keySet().iterator(); while (columns.hasNext()) { String field = (String)columns.next(); @@ -179,7 +179,7 @@ sb.append("\n"); } } - + sb.append("where\n"); Iterator conditions = m_conditions.iterator(); @@ -193,7 +193,7 @@ return sb.toString(); } - protected void addColumn(String field, + protected void addColumn(String field, String propName) { Assert.unlocked(this); m_columns.put(field, propName); @@ -204,32 +204,32 @@ Assert.unlocked(this); m_tables.put(table, alias); } - + protected void addCondition(String condition) { Assert.unlocked(this); m_conditions.add(condition); } - + protected String cleanSearchString(String terms) { return SimpleSearchSpecification.cleanSearchString(terms, " and "); } - + protected void addFilters(DataQuery query, FilterSpecification[] filters) { Assert.locked(this); for (int i = 0 ; i < filters.length ; i++) { - s_log.debug("adding filter " + filters[i]); + s_log.debug("adding filter " + filters[i]); addFilter(query, filters[i]); } } - + protected void addFilter(DataQuery query, FilterSpecification filter) { Assert.locked(this); FilterType type = filter.getType(); - + if (PermissionFilterType.KEY.equals(type.getKey())) { addPermissionFilter(query, (PermissionFilterSpecification)filter); } else if (ObjectTypeFilterType.KEY.equals(type.getKey())) { @@ -237,11 +237,11 @@ } else if (CategoryFilterType.KEY.equals(type.getKey())) { addCategoryFilter(query, (CategoryFilterSpecification)filter); } else if (ContentSectionFilterType.KEY.equals(type.getKey())) { - s_log.debug("adding the ContentSectionFilterSpecification filter"); - addContentSectionFilter(query, (ContentSectionFilterSpecification)filter); - } + s_log.debug("adding the ContentSectionFilterSpecification filter"); + addContentSectionFilter(query, (ContentSectionFilterSpecification)filter); + } } - + protected void addPermissionFilter(DataQuery query, PermissionFilterSpecification filter) { Assert.locked(this); @@ -286,36 +286,43 @@ ids.add(categories[i].getID()); } - Filter f = query.addInSubqueryFilter( - "object_id", - "id", - "com.arsdigita.search.categoryObjects"); - + Filter f = null; + if (filter.shouldDescend()) { + f = query.addInSubqueryFilter( + "object_id", + "id", + "com.arsdigita.search.categoryObjectsDescend"); + } else { + f = query.addInSubqueryFilter( + "object_id", + "id", + "com.arsdigita.search.categoryObjects"); + } f.set("ids", ids); } } protected void addContentSectionFilter(DataQuery query, - ContentSectionFilterSpecification filter) { - Assert.locked(this); + ContentSectionFilterSpecification filter) { + Assert.locked(this); Object[] contentSections = filter.getSections(); - s_log.debug("there are " + contentSections.length + " contentSections"); - if (contentSections != null && contentSections.length > 0) { - List contentSectionsList = Arrays.asList(contentSections); - Iterator i = contentSectionsList.iterator(); - StringBuffer filterSql = new StringBuffer(); - while (i.hasNext()) { - filterSql.append("content_section = '"); - filterSql.append((String)i.next()); - filterSql.append("'"); - if (i.hasNext()) { - filterSql.append(" or "); - } - } - s_log.debug("filterSql is " + filterSql.toString()); - query.addFilter(filterSql.toString()); - } + s_log.debug("there are " + contentSections.length + " contentSections"); + if (contentSections != null && contentSections.length > 0) { + List contentSectionsList = Arrays.asList(contentSections); + Iterator i = contentSectionsList.iterator(); + StringBuffer filterSql = new StringBuffer(); + while (i.hasNext()) { + filterSql.append("content_section = '"); + filterSql.append((String)i.next()); + filterSql.append("'"); + if (i.hasNext()) { + filterSql.append(" or "); + } + } + s_log.debug("filterSql is " + filterSql.toString()); + query.addFilter(filterSql.toString()); + } } - + } |