Class LuceneCategorySearchEngine

  • All Implemented Interfaces:
    JcmsConstants, CategorySearchEngine, JaliosConstants

    public class LuceneCategorySearchEngine
    extends LuceneDataSearchEngine
    implements CategorySearchEngine, JcmsConstants
    This CategorySearchEngine is reponsible for the indexing and searching of JCMS content using lucene.

    Architecture and notable points:
    • 1 lucene index per language: WEB-INF/data/lucene/CategoriesIndices/<lang>/.
    • 1 Document per indexed Category.
    • Indices' optimization occurs using schedule specified by property "search-engine.optimize-schedule" (jdring's AlarmEntry cron-like format)

    Possible Hooks/Modification:
    • Specify analyzer for each language: Analyzer getAnalyzer(String lang);
    Since:
    jcms-5.5.0
    Version:
    $Revision: 129677 $
    • Field Detail

      • MATCHED_CATEGORIES_ATTRIBUTE

        public static final java.lang.String MATCHED_CATEGORIES_ATTRIBUTE
        This variable is the attribute's key used by the LuceneCategorySearchEngine to set the matched categories HashSet in the QueryResultSet Attribute.
        See Also:
        Constant Field Values
      • CATEGORY_ENGINE_NAME

        protected static final java.lang.String CATEGORY_ENGINE_NAME
        See Also:
        Constant Field Values
      • CATEGORY_INDEX_DIRECTORY

        protected static final java.lang.String CATEGORY_INDEX_DIRECTORY
        See Also:
        Constant Field Values
      • DESCRIPTION_FIELD

        public static final java.lang.String DESCRIPTION_FIELD
        See Also:
        Constant Field Values
    • Constructor Detail

      • LuceneCategorySearchEngine

        public LuceneCategorySearchEngine()
                                   throws java.lang.Exception
        Initialize the Lucene Search Engine
        Throws:
        java.lang.Exception - if error occurs during initialization
    • Method Detail

      • add

        public void add​(Category cat)
        Add given Category to this lucene search engine.
        Specified by:
        add in interface CategorySearchEngine
        Parameters:
        cat - the Category to index .
      • update

        public void update​(Category cat)
        Update given Category in this lucene search engine.
        Specified by:
        update in interface CategorySearchEngine
        Parameters:
        cat - the Category to reindex .
      • delete

        public void delete​(Category cat)
        Delete given Category from this lucene search engine.
        Specified by:
        delete in interface CategorySearchEngine
        Parameters:
        cat - the Category to reindex .
      • add

        public void add​(java.util.Collection<Category> coll)
        Add given Collection of Category to this lucene search engine.
        Specified by:
        add in interface CategorySearchEngine
        Parameters:
        coll - the Collection of Category to index .
      • update

        public void update​(java.util.Collection<Category> coll)
        Update given Collection of Category in this lucene search engine.
        Specified by:
        update in interface CategorySearchEngine
        Parameters:
        coll - the Collection of Category to reindex .
      • delete

        public void delete​(java.util.Collection<Category> coll)
        Delete given Collection of Category from this lucene search engine.
        Specified by:
        delete in interface CategorySearchEngine
        Parameters:
        coll - the Collection of Category to reindex .
      • getIndexingDate

        public java.util.Date getIndexingDate​(Category cat)
        Retrieve the Date at which the specified Category was indexed in the search engine.
        Specified by:
        getIndexingDate in interface CategorySearchEngine
        Parameters:
        cat - the Category for which to retrieve the indexing date.
        Returns:
        the indexing date of the category or null if was not indexed.
        Since:
        jcms-6.0.1
      • search

        public boolean search​(QueryHandler qh,
                              java.util.HashSet<? extends Publication> pubSet,
                              QueryResultSet resultSet)
        Description copied from interface: CategorySearchEngine
        Perform a full-text search.
        Specified by:
        search in interface CategorySearchEngine
        Parameters:
        qh - the Queryhandler in which to find search text and search options.
        pubSet - a HashSet containing all the Publication to search.
        if empty, search is not performed at all.
        if null, all Publication found will be returned.
        This set MUST NOT be modified by implementation.
        resultSet - the QueryResultSet that must be filled with matching Publication
        Returns:
        true if a search was performed in the CategorySearchEngine. Useful to differenciate a query returning zero result from a query not performed due to missing paramerters (text for example).
      • getMaximumResults

        public static int getMaximumResults()
        Retrieve the maximum number of results allowed to be return for a search.

        Can be configured using property query.lucene.cat.max-results

        Returns:
        a maximum number of result retrieve (result beyong this limit are ignored)
        Since:
        jcms-10.0.0
      • searchCategories

        public java.util.Collection<Category> searchCategories​(QueryHandler qh)
        Find Category matching the specified QueryHandler search options (uses mainly the text search param)
        Parameters:
        qh - the QueryHandler used to store
        Returns:
        a collection of Category, ordered by relevance
        Since:
        jcms-7.1
      • searchCategories

        public java.util.Collection<Category> searchCategories​(org.apache.lucene.search.Query query)
        Find Category matching the specified lucene Query
        Parameters:
        query - a Lucene Query
        Returns:
        a collection of Category, ordered by relevance
        Since:
        jcms-7.1
      • getLogger

        protected org.apache.log4j.Logger getLogger()
        Description copied from class: LuceneDataSearchEngine
        This methods must be implemented by the LuceneSearchEngine. It must return the logger to be used for log messages.
        Specified by:
        getLogger in class LuceneDataSearchEngine
        Returns:
        Logger of this engine.
      • indexData

        protected void indexData​(org.apache.lucene.index.IndexWriter writer,
                                 Data data,
                                 java.lang.String lang)
                          throws java.io.IOException
        This methods index the given Category in the given language, into the given index writer.
        Specified by:
        indexData in class LuceneDataSearchEngine
        Throws:
        java.io.IOException
      • addUnStoredField

        protected void addUnStoredField​(org.apache.lucene.document.Document doc,
                                        Category cat,
                                        java.lang.String lang,
                                        java.lang.String fieldName,
                                        java.lang.String fieldValue,
                                        boolean applyBoost)
        This methods create a unstored Lucene Field with the given field's value of the given Category in the given language, and add into the given Document.
        Parameters:
        doc - the Lucene document
        cat - the category
        lang - the language
        fieldName - the field's name
        fieldValue - the field's value
        applyBoost - whether to apply the boost, useful for appendable field in which case the boost should only be applied for the first element.
      • addKeywordField

        protected void addKeywordField​(org.apache.lucene.document.Document doc,
                                       Category cat,
                                       java.lang.String lang,
                                       java.lang.String fieldName,
                                       java.lang.String fieldValue,
                                       boolean applyBoost)
        This methods create a unstored Lucene Field with the given field's value of the given Category in the given language, and add into the given Document.
        Parameters:
        doc - the Lucene document
        cat - the category
        lang - the language
        fieldName - the field's name
        fieldValue - the field's value
        applyBoost - whether to apply the boost, useful for appendable field in which case the boost should only be applied for the first element.