Package in.cdac.medinfo.csnotk.csnolib.agents

## Class LuceneSearchAgent

- java.lang.Object
- - in.cdac.medinfo.csnotk.csnolib.agents.LuceneSearchAgent

- All Implemented Interfaces:
    `ISearchAgent`, `java.io.Serializable`

      public class LuceneSearchAgent
      extends java.lang.Object
      implements ISearchAgent

  Implementation of document search functionality with Lucene version 8.7.0. Search functionality and implementation of index creation is provided by this class.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `LuceneSearchAgent()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addExtensionDetailsForIndexing​(java.util.Set<java.lang.String> moduleIdSet)` | This method is use to index distinct refsetid with respective name
    `boolean` | `checkDirectory​(java.lang.String indexDirectory)` | Checks whether the given (index) directory exists.
    `boolean` | `createIndex​(java.lang.String refsetId, java.util.Set<java.lang.String> moduleIdSet, boolean flag, boolean isconcreteRelPresent)` | *@param refsetId Identifier of Refset Lucene index creation utility.
    `boolean` | `deleteDataDirectory​(java.lang.String dataDir)` | Delete data directory content at the time Creating International indexing
    `void` | `deleteExtensionDocument​(java.lang.String refsetId, java.lang.String moduleId, java.lang.String queryConstant)` | For Deleting the old created index of extension.
    `boolean` | `deleteIndex​(java.lang.String refsetId)` | For Deleting the old index.
    `void` | `deleteRefsetDocument​(java.lang.String refsetId)` | For Deleting the old created index of refset.
    `java.util.Set<Concept>` | `getAllConceptsForWildcard​(org.apache.lucene.search.BooleanQuery.Builder builder)` | Searches for all `Concept`s in SNOINDEX (wildcard query).
    `java.util.Set<Refset>` | `getAllExtension()` | Returns a `Set` of all Extension.
    `java.util.Set<Refset>` | `getAllRefset()` | Returns a `Set` of all Refset.
    `Concept` | `getConceptDetails​(java.lang.String conceptId)` | Searches given conceptId in the SNOMED CT repository and returns `Concept` suited for ECL reponse.
    `java.util.List<Relationship>` | `getConcepts​(java.util.HashMap<java.lang.String,​java.util.List<java.lang.String>> queryParams)` | Searches the concepts of attribute name and attribute value.
    `java.util.Set<Concept>` | `getConceptsFromQuery​(org.apache.lucene.search.BooleanQuery.Builder builder)` | Searches for all `Concept`s having the (attribute-value) relationship stated in query.
    `long` | `getExtensionCountFromIndex​(java.lang.String refConceptId)` | Returns count of members of an Extension from the Index.
    `java.util.Set<Concept>` | `getExtensionMember​(java.lang.String moduleId, int pageNumber)` | Returns a `Set` of all Descendants `Concept`s for given concept identifier.
    `java.util.Set<RelationshipTC>` | `getIsARelationshipsWithCount​(java.lang.String conceptId)` | Searches for the immediate children descriptions.
    `java.util.Set<Concept>` | `getRefsetMember​(java.lang.String refsetId)` | Returns a `Set` of all Descendants `Concept`s for given concept identifier.
    `java.util.List<Relationship>` | `getRelationships​(java.lang.String conceptId, EnumRelationshipType enumRelationshipType, EnumDirection directions)` |
    `java.util.List<Relationship>` | `getRelationships​(java.lang.String conceptId, java.lang.String relationshipType, EnumDirection directions)` | Searches given concept id in the SNOMED CT repository based on provided relationship type, direction.
    `java.util.List<java.lang.String>` | `getRelationType()` | It will return all relationship type based on provided SNOMED CT RF2
    `java.util.Set<java.lang.String>` | `getSemanticTags()` | It will return all semantic tags based on provided SNOMED CT RF2
    `Concept` | `search​(java.lang.String conceptId)` | Searches given conceptId in the SNOMED CT repository
    `java.util.Set<CompositeDescription>` | `search​(java.util.HashMap<java.lang.String,​java.util.List<java.lang.String>> queryParams, boolean fullConcept)` | Searches given term/text or concept id in the SNOMED CT repository based on provided component state, semantic tag, acceptability.
    `SimpleMapRefsetResult` | `searchSimpleMap​(java.lang.String refsetComponentId)` | Searches the simpleMapTarget of refsetComponentId provided .
    `java.util.Set<Concept>` | `searchTC​(java.lang.String id)` | Searches given concept id in the SNOMED CT repository.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LuceneSearchAgent

          public LuceneSearchAgent()

  - ### Method Detail

    - #### deleteDataDirectory

          public boolean deleteDataDirectory​(java.lang.String dataDir)
                                      throws java.lang.SecurityException,
                                             java.io.IOException

      Delete data directory content at the time Creating International indexing
      Parameters:
        `dataDir` - -`String` dataDir path location
      Returns:
        `Boolean` True/False on the basis of job done
      Throws:
        `java.lang.SecurityException` - If file/directory does not allow to delete.
        `java.io.IOException`

    - #### createIndex

          public boolean createIndex​(java.lang.String refsetId,
                                     java.util.Set<java.lang.String> moduleIdSet,
                                     boolean flag,
                                     boolean isconcreteRelPresent)

      *@param refsetId Identifier of Refset Lucene index creation utility.

    - #### deleteIndex

          public boolean deleteIndex​(java.lang.String refsetId)

      For Deleting the old index.
      Parameters:
        `refsetId` - Identifier of Refset/RelationIndex/TCIndex for deleting the old created index.

    - #### search

          public java.util.Set<CompositeDescription> search​(java.util.HashMap<java.lang.String,​java.util.List<java.lang.String>> queryParams,
                                                            boolean fullConcept)

      Searches given term/text or concept id in the SNOMED CT repository based on provided component state, semantic tag, acceptability.
      Specified by:
        `search` in interface `ISearchAgent`
      Parameters:
        `queryParams` - Hashmap containing key value pair of search parameters on the basis of which search criteria will be decided. Parameters are as follows,
        SearchTerm - `String` term/text or Concept ID to be searched in SNOMED CT repository.
        State - `EnumState` State of a component.
        If enumState is,
        active - It will return only active Components.
        inactive - It will return only inactive Components.
        both - It will return both active and inactive Components.
        SemanticTag - `EnumSemanticTag` Refers to the Semantic Tag in which SNOMED CT term/text or concept id will be searched.
        If enumSemanticTag is,
        all - It will search SNOMED CT term in all the Semantic Tags.
        For other possible values please refer `EnumSemanticTag`.
        A list of `EnumSemanticTag` can also be provide in which search/suggest is to be perform.
        Acceptability - `EnumAcceptability` Represents the type of description i.e. whether the search results contains preferred terms or preferred terms other than FSN or only acceptable terms and so on.
        If enumAcceptability is,
        all - refers to all description for a concept (both preferred and acceptable).
        preferred - refers to all preferred description for a concept (including FSN).
        preferredexcludingfsn - refers to SNOMEDCT description for preferred terms excluding FSN.
        synonyms - refers to all description for a concept (excluding FSN).
        acceptable- refers to all description for a concept excluding preferred.
        returnLimit/MaxRecords - Maximum number of matching terms to be fetched.
        groupByConcept - boolean value, if true, then method will return set of `CompositeDescription` which will contain one description from one concept.
        refsetId - Identifier of Refset from which search is to be done and null if search is to be done from whole SNOMED CT Terminology
      Returns:
        Set of `CompositeDescription` matching the given term/text or Concept ID.

    - #### search

          public Concept search​(java.lang.String conceptId)
                         throws java.io.IOException,
                                java.text.ParseException,
                                org.apache.lucene.queryparser.classic.ParseException

      Searches given conceptId in the SNOMED CT repository
      Specified by:
        `search` in interface `ISearchAgent`
      Parameters:
        `conceptId` - String it will search on the basis of given conceptId and also use for checking the entered conceptId is valid or not
      Returns:
        Object of `Concept` respected to given conceptId
      Throws:
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`
        `java.text.ParseException`

    - #### getRelationships

          public java.util.List<Relationship> getRelationships​(java.lang.String conceptId,
                                                               java.lang.String relationshipType,
                                                               EnumDirection directions)

      Description copied from interface: `ISearchAgent`
      Searches given concept id in the SNOMED CT repository based on provided relationship type, direction.
      Specified by:
        `getRelationships` in interface `ISearchAgent`
      Parameters:
        `conceptId` - - `String` Concept ID to be searched in SNOMED CT repository.
        enumRelationshipType - `EnumRelationshipType` Type of relationship.
        If enumRelationshipType is,
        is a - It will return only "is a" relation type Components.
        all - It will return only "all" relation type Components.
        finding site - It will return only "finding site" relation type Components.
        directions- `EnumDirection` Relationship direction i.e whether the specified concept Id is the source or destination Possible values for directions is,
        source - concept Id is a source
        destination - concept Id is a destination
      Returns:
        List of `Relationship` matching the given term/text or Concept ID.

    - #### getRelationships

          public java.util.List<Relationship> getRelationships​(java.lang.String conceptId,
                                                               EnumRelationshipType enumRelationshipType,
                                                               EnumDirection directions)

    - #### searchTC

          public java.util.Set<Concept> searchTC​(java.lang.String id)
                                          throws java.text.ParseException

      Searches given concept id in the SNOMED CT repository. returnLimit/MaxRecords - Maximum number of matching terms to be fetched.
      refsetId - Identifier of Refset from which search is to be done and null if search is to be done from whole SNOMED CT Terminology
      Specified by:
        `searchTC` in interface `ISearchAgent`
      Parameters:
        `id` - concept id in the SNOMED CT
      Returns:
        Set of `RelationshipTC` matching the given Concept ID.
      Throws:
        `java.text.ParseException`

    - #### deleteExtensionDocument

          public void deleteExtensionDocument​(java.lang.String refsetId,
                                              java.lang.String moduleId,
                                              java.lang.String queryConstant)
                                       throws java.io.IOException

      For Deleting the old created index of extension.
      Parameters:
        `refsetId` - Identifier of Refset
      Throws:
        `java.io.IOException`

    - #### getConcepts

          public java.util.List<Relationship> getConcepts​(java.util.HashMap<java.lang.String,​java.util.List<java.lang.String>> queryParams)
                                                   throws java.io.IOException,
                                                          java.text.ParseException,
                                                          org.apache.lucene.queryparser.classic.ParseException

      Searches the concepts of attribute name and attribute value.
      Specified by:
        `getConcepts` in interface `ISearchAgent`
      Parameters:
        `queryParams` -
      Returns:
        List of `Relationship` matching the given Concept ID.
      Throws:
        `java.io.IOException`
        `org.apache.lucene.queryparser.classic.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.text.ParseException`

    - #### checkDirectory

          public boolean checkDirectory​(java.lang.String indexDirectory)

      Checks whether the given (index) directory exists.
      Parameters:
        `indexDirectory` -
      Returns:
        boolean value true/false

    - #### getSemanticTags

          public java.util.Set<java.lang.String> getSemanticTags()
                                                          throws org.apache.lucene.queryparser.classic.ParseException,
                                                                 java.io.IOException

      Description copied from interface: `ISearchAgent`
      It will return all semantic tags based on provided SNOMED CT RF2
      Specified by:
        `getSemanticTags` in interface `ISearchAgent`
      Returns:
        Set<`String`> Set of `String` containing semantic tags
      Throws:
        `java.text.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`

    - #### getRelationType

          public java.util.List<java.lang.String> getRelationType()
                                                           throws org.apache.lucene.queryparser.classic.ParseException,
                                                                  java.io.IOException

      Description copied from interface: `ISearchAgent`
      It will return all relationship type based on provided SNOMED CT RF2
      Specified by:
        `getRelationType` in interface `ISearchAgent`
      Returns:
        List<`String`> List of `String` containing relationship type name
      Throws:
        `java.text.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`

    - #### searchSimpleMap

          public SimpleMapRefsetResult searchSimpleMap​(java.lang.String refsetComponentId)
                                                throws java.text.ParseException,
                                                       java.io.IOException,
                                                       org.apache.lucene.queryparser.classic.ParseException

      Searches the simpleMapTarget of refsetComponentId provided .
      Specified by:
        `searchSimpleMap` in interface `ISearchAgent`
      Parameters:
        `queryParams` -
      Returns:
        SimpleMapRefsetResult mapped to the given Refset Component ID.
      Throws:
        `java.io.IOException`
        `org.apache.lucene.queryparser.classic.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.text.ParseException`

    - #### getIsARelationshipsWithCount

          public java.util.Set<RelationshipTC> getIsARelationshipsWithCount​(java.lang.String conceptId)

      Searches for the immediate children descriptions.
      Specified by:
        `getIsARelationshipsWithCount` in interface `ISearchAgent`
      Parameters:
        `conceptId` - Concept Id whose immediate children to search
      Returns:
        Set of `RelationshipTC` matching the given Concept ID.
      Throws:
        `java.io.IOException` - if any error occurs while processing.
        `java.text.ParseException`

    - #### addExtensionDetailsForIndexing

          public void addExtensionDetailsForIndexing​(java.util.Set<java.lang.String> moduleIdSet)

      This method is use to index distinct refsetid with respective name
      Parameters:
        `refsetIdList` - contains refsetid , refset term
        `refsetId` -

    - #### getAllRefset

          public java.util.Set<Refset> getAllRefset()
                                             throws org.apache.lucene.queryparser.classic.ParseException,
                                                    java.io.IOException,
                                                    java.text.ParseException

      Returns a `Set` of all Refset.
      Specified by:
        `getAllRefset` in interface `ISearchAgent`
      Returns:
        Set of `Refset`s.
      Throws:
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`

    - #### getAllExtension

          public java.util.Set<Refset> getAllExtension()
                                                throws org.apache.lucene.queryparser.classic.ParseException,
                                                       java.io.IOException,
                                                       java.text.ParseException

      Returns a `Set` of all Extension.
      Specified by:
        `getAllExtension` in interface `ISearchAgent`
      Returns:
        Set of `Refset`s.
      Throws:
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`

    - #### getRefsetMember

          public java.util.Set<Concept> getRefsetMember​(java.lang.String refsetId)
                                                 throws org.apache.lucene.queryparser.classic.ParseException,
                                                        java.io.IOException,
                                                        java.text.ParseException

      Returns a `Set` of all Descendants `Concept`s for given concept identifier.
      Specified by:
        `getRefsetMember` in interface `ISearchAgent`
      Parameters:
        `id` - SNOMED CT concept identifier.
      Returns:
        Set of `Concept`s.
      Throws:
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`

    - #### getExtensionMember

          public java.util.Set<Concept> getExtensionMember​(java.lang.String moduleId,
                                                           int pageNumber)
                                                    throws org.apache.lucene.queryparser.classic.ParseException,
                                                           java.io.IOException,
                                                           java.text.ParseException

      Returns a `Set` of all Descendants `Concept`s for given concept identifier. Used for Extension Member records.
      Specified by:
        `getExtensionMember` in interface `ISearchAgent`
      Parameters:
        `id` - SNOMED CT concept identifier.
        `pageNumber` - records to load for a specific page (pagination).
      Returns:
        Set of `Concept`s.
      Throws:
        `org.apache.lucene.queryparser.classic.ParseException`
        `java.io.IOException`

    - #### getExtensionCountFromIndex

          public long getExtensionCountFromIndex​(java.lang.String refConceptId)

      Returns count of members of an Extension from the Index.
      Parameters:
        `refConceptId` - Module Identifier .
      Returns:
        extensionCount the total number of rows stored in index.

    - #### deleteRefsetDocument

          public void deleteRefsetDocument​(java.lang.String refsetId)
                                    throws java.io.IOException

      For Deleting the old created index of refset.
      Parameters:
        `refsetId` - Identifier of Refset
        `indexWriter` -
      Throws:
        `java.io.IOException`

    - #### getConceptsFromQuery

          public java.util.Set<Concept> getConceptsFromQuery​(org.apache.lucene.search.BooleanQuery.Builder builder)
                                                      throws java.io.IOException,
                                                             java.text.ParseException

      Searches for all `Concept`s having the (attribute-value) relationship stated in query.
      Parameters:
        `builder` - `BooleanQuery` query object (based on the type of attribute - value relationship).
      Returns:
        Set of `Concept`s.
      Throws:
        `java.io.IOException`
        `java.text.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`

    - #### getConceptDetails

          public Concept getConceptDetails​(java.lang.String conceptId)
                                    throws java.io.IOException,
                                           java.text.ParseException,
                                           org.apache.lucene.queryparser.classic.ParseException

      Searches given conceptId in the SNOMED CT repository and returns `Concept` suited for ECL reponse.
      Parameters:
        `conceptId` - `String` search on the basis of given conceptId.
      Returns:
        Object of `Concept` respected to given conceptId
      Throws:
        `java.io.IOException`
        `java.text.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`

    - #### getAllConceptsForWildcard

          public java.util.Set<Concept> getAllConceptsForWildcard​(org.apache.lucene.search.BooleanQuery.Builder builder)
                                                           throws java.io.IOException,
                                                                  java.text.ParseException,
                                                                  org.apache.lucene.queryparser.classic.ParseException

      Searches for all `Concept`s in SNOINDEX (wildcard query).
      Parameters:
        `builder` - `BooleanQuery` query object (all active concepts).
      Returns:
        Set of `Concept`s.
      Throws:
        `java.io.IOException`
        `java.text.ParseException`
        `org.apache.lucene.queryparser.classic.ParseException`