Class QueryManager

java.lang.Object
com.jalios.jcms.QueryManager
All Implemented Interfaces:
JcmsConstants, JaliosConstants

public class QueryManager extends Object implements JcmsConstants
This class manages queries on publications
Since:
jcms-5.0.0
Author:
Olivier Dedieu, Olivier Jaquemet
  • Field Details

    • QUERY_MANAGER_STEP_ATTRIBUTE

      public static final String QUERY_MANAGER_STEP_ATTRIBUTE
      QueryHandler attribute key of the current QueryManager processing step of the QueryManager.
      See Also:
    • queryFilterSet

      protected Set<QueryFilter> queryFilterSet
    • idCount

      protected int idCount
  • Method Details

    • getQueryManager

      public static QueryManager getQueryManager()
    • getInstance

      public static QueryManager getInstance()
    • getPublicationSearchEngine

      public PublicationSearchEngine getPublicationSearchEngine()
      Returns:
      the PublicationSearchEngine
      Since:
      jcms-5.5.0
    • getCategorySearchEngine

      public CategorySearchEngine getCategorySearchEngine()
      Returns:
      the CategorySearchEngine
      Since:
      jcms-5.5.0
    • addQueryFilter

      public void addQueryFilter(QueryFilter qf)
      Add the given QueryFilter.
      Parameters:
      qf - the QueryFilter to be added
      Since:
      jcms-5.0.0
    • removeQueryFilter

      public void removeQueryFilter(QueryFilter qf)
      Remove the given QueryFilter.
      Parameters:
      qf - the QueryFilter to be removed
      Since:
      jcms-5.0.0
    • getQueryFilterSet

      public Set<QueryFilter> getQueryFilterSet()
      Returns all the query filter. DO NOT alter the returned set, clone prior modification.
      Returns:
      the queryFilterSet
      Since:
      jcms-5.5.0
    • prepareExternalResult

      public void prepareExternalResult(Publication pub)
      Prepare the given publication to be displayed in the result list. Fill the publication with fake id, cdate, mdate and pdate, and author.
      Parameters:
      pub - the publication to be prepared
      Since:
      jcms-5.0.0
    • query

      public QueryResultSet query(QueryHandler qh, javax.servlet.ServletRequest request, Set<? extends Publication> proposedDataSet)
      Perform a query using parameters specified in the given QueryHandler.
      Search in the given Collection of Publication or in all Publication if not specified.
      Parameters:
      qh - the QueryHandler from which to retrieve the query parameters, MUST NOT be null.
      request - the ServletHttpRequest used to set some error or warning messages in the attributes, can be null.
      proposedDataSet - the Collection of Publication in which to search and apply query parameters, if null, search is done in all Publication.
      Returns:
      a QueryResultSet containing all results of this query, it is a HashSet and therefore it is NOT sorted. use either QueryResultSet.getAsSortedSet() or QueryResultSet.getAsSortedSet(java.util.Comparator) to obtain a sorted Set.
      Since:
      jcms-5.0.0
    • performJStoreQuery

      protected QueryResultSet performJStoreQuery(QueryHandler qh, javax.servlet.http.HttpServletRequest request, Set<? extends Publication> proposedDataSet)
      Parameters:
      qh - the queryHandler
      request - the request
      proposedDataSet - the proposed data set
      Returns:
      see QueryManager#query(QueryHandler, ServletRequest, Set)
      See Also:
    • getDateType

      protected static int getDateType(QueryHandler qh)
      Return an integer describing the type of search date from a QueryHandler.
      Parameters:
      qh - the QueryHandler to use.
      Returns:
      an integer, see ?DATE_SEARCH constants.
    • getBeginAndEndDates

      protected Date[] getBeginAndEndDates(QueryHandler qh)
      Compute begin and end date of a query from QueryHandler values.
      Parameters:
      qh - the QueryHandler to use.
      Returns:
      an array of two Date, the first is the begin date, the second the end Date.
    • getQueryCategorySet

      protected HashSet<Category> getQueryCategorySet(QueryHandler qh)
      Compute a HashSet of Category to include during query from the "cids" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Category
    • getQueryAvoidCategorySet

      protected HashSet<Category> getQueryAvoidCategorySet(QueryHandler qh)
      Compute a HashSet of Category to exclude during query from the "cidsOff" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Category
    • getQueryMemberSet

      protected HashSet<Member> getQueryMemberSet(QueryHandler qh)
      Compute a HashSet of Member to include during query from the "mids" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Member
    • getQueryAvoidMemberSet

      protected HashSet<Member> getQueryAvoidMemberSet(QueryHandler qh)
      Compute a HashSet of Member to exclude during query from the "midsOff" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Member
    • getQueryGroupSet

      protected HashSet<Group> getQueryGroupSet(QueryHandler qh)
      Compute a HashSet of Group to include during query from the "gids" value of the given QueryHandler. Return null if the computed hashset is empty.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Group
    • getQueryAvoidGroupSet

      protected HashSet<Group> getQueryAvoidGroupSet(QueryHandler qh)
      Compute a HashSet of Group to exclude during query from the "gidsOff" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Group
    • getQueryPortalElementSet

      protected HashSet<PortalElement> getQueryPortalElementSet(QueryHandler qh)
      Compute a HashSet of PortalElement including all portal ands its children from the "portalIds" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of PortalElement
    • getQueryClassSet

      protected HashSet<Class<? extends Publication>> getQueryClassSet(QueryHandler qh, boolean addFileDoc)
      Compute a HashSet of Class (type) to include during query from the "types" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      addFileDoc - if true add the FileDocument class
      Returns:
      a HashSet of Class
    • getQueryAvoidClassSet

      protected HashSet<Class<? extends Publication>> getQueryAvoidClassSet(QueryHandler qh)
      Compute a HashSet of Class (type) to include during query from the "typesOff" value of the given QueryHandler.
      Parameters:
      qh - the QueryHandler
      Returns:
      a HashSet of Class
    • reduceDataSetWithTextEngine

      protected void reduceDataSetWithTextEngine(QueryHandler qh, HashSet<Publication> dataToKeepSet, HashSet<Publication> dataToExcludeSet, boolean[] indexUsed)
      Fill the given HashSet with Data to keep and to exclude using Text Search options of the QueryHandler.
      Parameters:
      qh - the QueryHandler
      dataToKeepSet - the set of data to keep
      dataToExcludeSet - the set of data to exclude
      indexUsed - a flag to mark if data set is to keep or to exclude
      Since:
      jcms-6.1.0
    • reduceDataSetWithTypes

      protected boolean reduceDataSetWithTypes(QueryHandler qh, HashSet<Publication> dataToKeepSet, HashSet<Publication> dataToExcludeSet, boolean[] indexUsed)
      Fill the given HashSet with Data to keep and to exclude using Types options (types/typesOff) of the QueryHandler.
      Parameters:
      qh - the QueryHandler
      dataToKeepSet - the set of data to keep
      dataToExcludeSet - the set of data to exclude
      indexUsed - a flag to mark if data set is to keep or to exclude
      Returns:
      true if the reduction using dataToKeepSet was performed, false otherwise.
    • reduceDataSetWithCategories

      protected void reduceDataSetWithCategories(QueryHandler qh, HashSet<Publication> dataToKeepSet, HashSet<Publication> dataToExcludeSet, boolean[] indexUsed)
      Fill the given HashSet with Data to keep and to exclude using Categories options (cids/cidsOff) of the QueryHandler.
      Parameters:
      qh - the QueryHandler
      dataToKeepSet - the set of data to keep
      dataToExcludeSet - the set of data to exclude
      indexUsed - a flag to mark if data set is to keep or to exclude
    • reduceDataSetWithMembers

      protected void reduceDataSetWithMembers(QueryHandler qh, HashSet<Publication> dataToKeepSet, HashSet<Publication> dataToExcludeSet, boolean[] indexUsed)
      Fill the given HashSet with Data to keep and to exclude using Members options (mids/midsOff) of the QueryHandler.
      Parameters:
      qh - the QueryHandler
      dataToKeepSet - the set of data to keep
      dataToExcludeSet - the set of data to exclude
      indexUsed - a flag to mark if data set is to keep or to exclude
    • reduceDataSetWithPortalElements

      protected void reduceDataSetWithPortalElements(QueryHandler qh, HashSet<Publication> dataToKeepSet, HashSet<Publication> dataToExcludeSet, boolean[] indexUsed)
      Fill the given HashSet with Data to keep and to exclude using PortalElement options (mids/midsOff) of the QueryHandler.
      Parameters:
      qh - the QueryHandler
      dataToKeepSet - the set of data to keep
      dataToExcludeSet - the set of data to exclude
      indexUsed - a flag to mark if data set is to keep or to exclude
    • reduceDataSetWithHistoryRefinement

      protected void reduceDataSetWithHistoryRefinement(QueryHandler qh, Set<? extends Publication> proposedDataSet, javax.servlet.http.HttpServletRequest request, HashSet<Publication> dataToKeepSet, HashSet<Publication> dataToExcludeSet, boolean[] indexUsed)
      Fill the given HashSet with Data to keep and to exclude using query History (hist) of the QueryHandler.

      Parameters:
      qh - the QueryHandler
      proposedDataSet - the proposed set of data to seach on.
      request - the request
      dataToKeepSet - the set of data to keep
      dataToExcludeSet - the set of data to exclude
      indexUsed - a flag to mark if data set is to keep or to exclude
    • searchFulltext

      protected boolean searchFulltext(QueryHandler qh, HashSet<Publication> dataSet, QueryResultSet resultSet)
      Perform a full-text search. It fills the given resultSet with results from the dataSet matching critera of qh.
      Parameters:
      qh - the Queryhandler
      dataSet - a HashSet containing all the publication to search.
      resultSet - a QueryResultSet in which to put all the results.
      Returns:
      true if the search has been performed.
      Since:
      jcms-5.0.0
    • matchLucenePublicationRefinement

      public static boolean matchLucenePublicationRefinement(QueryHandler qh, Publication pub)
    • callFilterDBResult

      public boolean callFilterDBResult(PublicationCriteria pubCriteria)
    • filterCriteria

      public void filterCriteria(PublicationCriteria pubCriteria, org.hibernate.Criteria criteria)
      Invoke all QueryFilter to allow them to modify the Hibernate Criteria used for a DB Query.
      Parameters:
      pubCriteria - the criteria of the query.
      criteria - the hibernate criteria computed by JPlatform core
      Since:
      jcms-10.0.7 / JCMS-9561
    • filterDBResult

      public boolean filterDBResult(Publication pub, Map context)
    • getRelatedPublicationSet

      public SortedSet<? extends Publication> getRelatedPublicationSet(Publication pub, Member mbr, Class... classes)
      Returns a set of publications related to the given publication and the given types for the given member.
      Parameters:
      pub - the publication to search related publications.
      mbr - the logged member
      classes - an array of publication classes
      Returns:
      a set of publications related to the given publication and the given types for the given member.
      Since:
      jcms-10.0.4
    • getRelatedPublicationSet

      public SortedSet<? extends Publication> getRelatedPublicationSet(Publication pub, QueryHandler qh)
      Returns a set of publications related to the given publication and the given query handler.
      Parameters:
      pub - the publication to search related publications.
      qh - the QueryHandler
      Returns:
      a set of publications related to the given publication and the given query handler.
      Since:
      jcms-10.0.0
    • getRelatedPublicationSet

      public SortedSet<? extends Publication> getRelatedPublicationSet(Set<Category> catSet, QueryHandler qh, Comparator<? extends Publication> superComparator)
      Returns a set of publications related to the given category set and the given query handler.
      Parameters:
      catSet - the set of category to search related publications.
      qh - the QueryHandler
      superComparator - if not null use this comparator in case of equality on the common category count.
      Returns:
      a set of publications related to the given category set and the given query handler.
      Since:
      jcms-10.0.0
    • getRelatedPublicationSet

      public SortedSet<? extends Publication> getRelatedPublicationSet(Set<Category> catSet, QueryHandler qh, Comparator<? extends Publication> superComparator, int max)
      Returns a set of publications related to the given category set and the given query handler.
      Parameters:
      catSet - the set of category to search related publications.
      qh - the QueryHandler
      superComparator - if not null use this comparator in case of equality on the common category count.
      max - the max of related publication returned
      Returns:
      a set of publications related to the given category set and the given query handler.
      Since:
      jcms-11.0.0