Class LucenePublicationSearchEngine

java.lang.Object
com.jalios.jcms.search.LuceneDataSearchEngine
com.jalios.jcms.search.LucenePublicationSearchEngine
All Implemented Interfaces:
JcmsConstants, PublicationSearchEngine, JaliosConstants

public class LucenePublicationSearchEngine extends LuceneDataSearchEngine implements PublicationSearchEngine, JcmsConstants
This PublicationSearchEngine 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/PublicationsIndices/<lang>/.
  • 1 Document per indexed Publication.
  • Date fields are indexed using "yyyyMMdd" format.
  • Only String and String[] fields are added to the common appendable field ALLFIELDS_FIELD used for searching.
  • 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
  • Field Details

    • SPELLSUGGEST_ATTRIBUTE

      public static final String SPELLSUGGEST_ATTRIBUTE
      This variable is the attribute's key used by the LucenePublicationSearchEngine to set the suggested search string in the QueryResultSet Attribute.
      See Also:
    • PUBLICATION_ENGINE_NAME

      protected static final String PUBLICATION_ENGINE_NAME
      See Also:
    • PUBLICATION_INDEX_DIRECTORY

      protected static final String PUBLICATION_INDEX_DIRECTORY
      See Also:
    • TITLE_FIELD

      public static final String TITLE_FIELD
      See Also:
    • ABSTRACT_FIELD

      public static final String ABSTRACT_FIELD
      See Also:
    • ALLFIELDS_FIELD

      public static final String ALLFIELDS_FIELD
      See Also:
    • CLASS_FIELD

      public static final String CLASS_FIELD
      See Also:
    • ISDBDATA_FIELD

      public static final String ISDBDATA_FIELD
      See Also:
    • AUTHORID_FIELD

      public static final String AUTHORID_FIELD
      See Also:
    • OPAUTHORID_FIELD

      public static final String OPAUTHORID_FIELD
      See Also:
    • PSTATUS_FIELD

      public static final String PSTATUS_FIELD
      See Also:
    • WORKSPACEID_FIELD

      public static final String WORKSPACEID_FIELD
      See Also:
    • CATEGORYID_FIELD

      public static final String CATEGORYID_FIELD
      See Also:
    • CLASSIFICATIONLEVEL_FIELD

      public static final String CLASSIFICATIONLEVEL_FIELD
      See Also:
    • CDATE_FIELD

      public static final String CDATE_FIELD
      See Also:
    • MDATE_FIELD

      public static final String MDATE_FIELD
      See Also:
    • UDATE_FIELD

      public static final String UDATE_FIELD
      See Also:
    • PDATE_FIELD

      public static final String PDATE_FIELD
      See Also:
    • SDATE_FIELD

      public static final String SDATE_FIELD
      See Also:
    • EDATE_FIELD

      public static final String EDATE_FIELD
      See Also:
    • ADATE_FIELD

      public static final String ADATE_FIELD
      See Also:
    • VERSION_FIELD

      public static final String VERSION_FIELD
      See Also:
    • FILEDOCUMENT_CONTENT_TYPE_FIELD

      public static final String FILEDOCUMENT_CONTENT_TYPE_FIELD
      Field name for the extension of the file , e.g. "txt", or IOUtil.getExtension(fileDoc.getFile())
      See Also:
    • FILEDOCUMENT_FILE_EXTENSION_FIELD

      public static final String FILEDOCUMENT_FILE_EXTENSION_FIELD
      Field name for the extension of the file , e.g. "txt", or IOUtil.getExtension(fileDoc.getFile())
      See Also:
    • FILEDOCUMENT_FILENAME_FIELD

      public static final String FILEDOCUMENT_FILENAME_FIELD
      Field name for the relative path in jcms, e.g. "upload/docs/file.txt", or fileDoc.getFilename()
      See Also:
    • FILEDOCUMENT_ORIGINAL_FILENAME_FIELD

      public static final String FILEDOCUMENT_ORIGINAL_FILENAME_FIELD
      Field name for the original filename as upload by user eg "My file.txt", or fileDoc.getOriginalFilename()
      See Also:
    • FILEDOCUMENT_MODIFIED_FIELD

      public static final String FILEDOCUMENT_MODIFIED_FIELD
      Field name for the last modified date of the file (time in ms) when it was indexed
      See Also:
    • FILEDOCUMENT_INDEXING_DATE_FIELD

      public static final String FILEDOCUMENT_INDEXING_DATE_FIELD
      Field name for the date at which the FileDocument has been indexed with a non empty content
      See Also:
    • FILEDOCUMENT_CONTENT

      public static final String FILEDOCUMENT_CONTENT
      Field name for the content of the file as extracted with additionnal parser in FileProcessor
      See Also:
    • HITS_TIMEOUT_PROP

      public static final String HITS_TIMEOUT_PROP
      See Also:
    • dateFormatter

      public static final DateFormat dateFormatter
    • RANK_CONSTANT_DEFAULT

      public static final int RANK_CONSTANT_DEFAULT
      Default Rank constants for Reciprocal Rank Fusion (RRF).
      See Also:
    • RANK_CONSTANT_PROP

      public static final String RANK_CONSTANT_PROP
      Property used to read the rank constant value for Reciprocal Rank Fusion (RRF).

      This value determines how much influence documents in individual result sets per query documents have more influence. This value must be greater than or equal to 1. Defaults to 60. have over the final ranked result set. A higher value indicates that lower ranked.

      See Also:
    • HITS_TIMEOUT

      protected static final long HITS_TIMEOUT
    • spellSuggestEngine

      protected SpellSuggestEngine spellSuggestEngine
  • Constructor Details

    • LucenePublicationSearchEngine

      public LucenePublicationSearchEngine() throws Exception
      Initialize the Lucene Search Engine
      Throws:
      Exception - if the Publication search engine could not be instanciated correctly
  • Method Details

    • add

      public void add(Publication pub)
      Add given Publication to this lucene search engine. This method is asynchronous, the given data may not be (and will certainly not be) added immediately after call.
      Specified by:
      add in interface PublicationSearchEngine
      Parameters:
      pub - the Publication to index .
    • update

      public void update(Publication pub)
      Update given Publication in this lucene search engine. This method is asynchronous, the given data may not be (and will certainly not be) updated immediately after call.
      Specified by:
      update in interface PublicationSearchEngine
      Parameters:
      pub - the Publication to reindex .
    • delete

      public void delete(Publication pub)
      Delete given Publication from this lucene search engine. This method is asynchronous, the given data may not be (and will certainly not be) deleted immediately after call.
      Specified by:
      delete in interface PublicationSearchEngine
      Parameters:
      pub - the Publication to reindex .
    • add

      public void add(Collection<? extends Publication> coll)
      Add given Collection of Publication to this lucene search engine. This method is asynchronous, the given datas may not be (and will certainly not be) added immediately after call.
      Specified by:
      add in interface PublicationSearchEngine
      Parameters:
      coll - the Collection of Publication to index .
    • update

      public void update(Collection<? extends Publication> coll)
      Update given Collection of Publication in this lucene search engine. This method is asynchronous, the given datas may not be (and will certainly not be) updated immediately after call.
      Specified by:
      update in interface PublicationSearchEngine
      Parameters:
      coll - the Collection of Publication to reindex .
    • delete

      public void delete(Collection<? extends Publication> coll)
      Delete given Collection of Publication from this lucene search engine. This method is asynchronous, the given datas may not be (and will certainly not be) deleted immediately after call.
      Specified by:
      delete in interface PublicationSearchEngine
      Parameters:
      coll - the Collection of Publication to reindex .
    • getIndexingDate

      public Date getIndexingDate(Publication pub)
      Retrieve the Date at which the specified Publication was indexed in the search engine.
      Specified by:
      getIndexingDate in interface PublicationSearchEngine
      Parameters:
      pub - the Publication for which to retrieve the indexing date.
      Returns:
      the indexing date of the publication or null if was not indexed.
      Since:
      jcms-6.0.1
    • getReindexAllAction

      protected AdminSearchEnginesHandler.Action getReindexAllAction()
      Description copied from class: LuceneDataSearchEngine
      Returns the AdminSearchEnginesHandler.Action to use when starting an AdminSearchEngineProcess for a full reindex.
      Specified by:
      getReindexAllAction in class LuceneDataSearchEngine
    • search

      public boolean search(QueryHandler qh, HashSet<? extends Publication> pubSet, QueryResultSet resultSet)
      Search for JStore Publication using lucene search engine.

      • Perform lucene text search using of QueryHandler.getText() which is required.
      • Add Publication into returned Set only if they are already in the given pubSet or if pubSet is null.
      • Caution! This method ignores all JcmsDB Publication.
      Specified by:
      search in interface PublicationSearchEngine
      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 PublicationSearchEngine. Useful to differenciate a query returning zero result from a query not performed due to missing paramerters (text for example).
      Since:
      jcms-5.5.0
    • 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.pub.max-results

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

      public LinkedHashMap<String,Float> search(QueryHandler qh)
      Search for JcmsDB Publication using lucene search engine.

      • Perform lucene text search using of QueryHandler.getText() which is required.
      • Add Publication into returned Set only if they are already in the given pubSet or if pubSet is null.
      • Caution! This method ignores all JStore Publication.
      Specified by:
      search in interface PublicationSearchEngine
      Parameters:
      qh - the Queryhandler in which to find search text and search options.
      Returns:
      a map of publication id and their score.
    • getSpellSuggestEngine

      public SpellSuggestEngine getSpellSuggestEngine()
    • getLogger

      protected org.apache.log4j.Logger getLogger()
      Description copied from class: LuceneDataSearchEngine
      Returns the Logger used for all log messages emitted by this engine.
      Specified by:
      getLogger in class LuceneDataSearchEngine
      Returns:
      Logger of this engine.
    • getDataIterator

      protected DataIterator<Data> getDataIterator(LuceneDataSearchEngine.ReindexOptions options)
      Description copied from class: LuceneDataSearchEngine
      Returns a DataIterator over all Data objects to be indexed, filtered according to the given LuceneDataSearchEngine.ReindexOptions.
      Specified by:
      getDataIterator in class LuceneDataSearchEngine
      Parameters:
      options - reindex configuration
      Returns:
      a non-null DataIterator
    • indexData

      protected void indexData(org.apache.lucene.index.IndexWriter writer, Data data, String lang, boolean isFullReindexing) throws IOException
      This methods index the given publication in the given language, into the given index writer.
      Specified by:
      indexData in class LuceneDataSearchEngine
      Parameters:
      writer - target Lucene writer
      data - the Data to index
      lang - ISO-639 language code
      isFullReindexing - true if operation is for a full reindexing with a empty index, false if updating an existing index
      Throws:
      IOException - on I/O error
    • addTextFieldStored

      public void addTextFieldStored(org.apache.lucene.document.Document doc, Publication pub, String lang, String fieldName, String fieldValue)
      This methods create a stored Lucene Field with the given field's value of the given Publication in the given language, and add into the given Document.
      Parameters:
      doc - the lucene Document in which field will be added
      pub - the publication for which field is added
      lang - the language in which field is added, if relevant
      fieldName - the name of the field in the lucene index
      fieldValue - the value of the field in the lucene index
    • addTextFieldNotStored

      public void addTextFieldNotStored(org.apache.lucene.document.Document doc, Publication pub, String lang, String fieldName, String fieldValue)
      This methods create a unstored Lucene Field with the given field's value of the given Publication in the given language, and add into the given Document.
      Parameters:
      doc - the lucene Document in which field will be added
      pub - the publication for which field is added
      lang - the language in which field is added, if relevant
      fieldName - the name of the field in the lucene index
      fieldValue - the value of the field in the lucene index
    • addStringFieldStored

      public void addStringFieldStored(org.apache.lucene.document.Document doc, Publication pub, String lang, String fieldName, String fieldValue)
      This methods create a stored Lucene Field with the given field's value of the given Publication in the given language, and add into the given Document.
      Parameters:
      doc - the lucene Document in which field will be added
      pub - the publication for which field is added
      lang - the language in which field is added, if relevant
      fieldName - the name of the field in the lucene index
      fieldValue - the value of the field in the lucene index
    • addStringFieldNotStored

      public void addStringFieldNotStored(org.apache.lucene.document.Document doc, Publication pub, String lang, String fieldName, String fieldValue)
      This methods create a unstored and untokenized Lucene Field with the given field's value of the given Publication in the given language, and add into the given Document.
      Parameters:
      doc - the lucene Document in which field will be added
      pub - the publication for which field is added
      lang - the language in which field is added, if relevant
      fieldName - the name of the field in the lucene index
      fieldValue - the value of the field in the lucene index