Class OneQuerySearch

  • All Implemented Interfaces:
    Runnable, nzilbb.util.MonitorableTask

    public class OneQuerySearch
    extends SearchTask
    Implementation of search that uses a single monolithic SQL query to identify matches.
    Author:
    Robert Fromont robert@fromont.net.nz
    • Constructor Detail

      • OneQuerySearch

        public OneQuerySearch()
    • Method Detail

      • generateSql

        public String generateSql​(Vector<Object> parameters,
                                  nzilbb.ag.Schema schema,
                                  Predicate<nzilbb.ag.Layer> layerIsSpanningAndWordAnchored,
                                  UnaryOperator<String> participantCondition,
                                  UnaryOperator<String> transcriptCondition)
                           throws Exception
        Create an SQL query that identifies results that match the search matrix patterns, filling in the given lists with information about parameters to set.
        Parameters:
        parameters - List of parameter values, which must be Double, Integer, or String.
        schema - The layer schema.
        layerIsSpanningAndWordAnchored - A predicate that determines whether the given layer is a phrase or span layer for which all annotations share anchors with words.
        participantCondition - Supplies the WHERE condition that identifies the target participants, presumably based on Matrix.participantQuery.
        transcriptCondition - Supplies the WHERE condition that identifies the target transcripts, presumably based on Matrix.transcriptQuery.
        Returns:
        An SQL query to implement the query.
        Throws:
        Exception - If the search should be halted for any reason - e.g. the Matrix.participantQuery identifies no participants.
      • generateOrthographySql

        public String generateOrthographySql​(Vector<Object> parameters,
                                             nzilbb.ag.Schema schema)
                                      throws Exception
        Create an SQL query that identifies results that match the search matrix patterns, optimised for a matrix that only searches the orthography layer, filling in the given lists with information about parameters to set.

        This implementation makes speed gains over generateSql(java.util.Vector<java.lang.Object>, nzilbb.ag.Schema, java.util.function.Predicate<nzilbb.ag.Layer>, java.util.function.UnaryOperator<java.lang.String>, java.util.function.UnaryOperator<java.lang.String>) by supporting only the orthography layer, and no border conditions, main-participant or transcript-type filtering. Allowing only plain, full-database searches of the orthography layer means that the initial search query can be completed with no SQL JOINs, meaning that searches can complete in something like one sixth of the time, on very large databases.

        Parameters:
        parameters - List of parameter values, which must be Double, Integer, or String.
        schema - The layer schema.
        Returns:
        An SQL query to implement the query.
        Throws:
        Exception - If the search should be halted for any reason - e.g. the Matrix.participantQuery identifies no participants.
      • keepAlive

        public void keepAlive()
        Somebody is still interested in the thread, so keep it from dying.
        Overrides:
        keepAlive in class Task
      • cancel

        public void cancel()
        Override to allow update-statement cancellation
        Specified by:
        cancel in interface nzilbb.util.MonitorableTask
        Overrides:
        cancel in class Task
      • IsSegmentLayer

        public static boolean IsSegmentLayer​(nzilbb.ag.Layer layer,
                                             nzilbb.ag.Schema schema)
        Determines whether the given layer is a 'segment' layer.
        Parameters:
        layer - The layer to test.
        schema - The schema the layer comes from.
        Returns:
        true if the given layer is the "segment" layer or a child of it.
      • IsWordLayer

        public static boolean IsWordLayer​(nzilbb.ag.Layer layer,
                                          nzilbb.ag.Schema schema)
        Determines whether the given layer is a 'word' layer.
        Parameters:
        layer - The layer to test.
        schema - The schema the layer comes from.
        Returns:
        true if the given layer is the word layer or a child of it.
      • IsPhraseLayer

        public static boolean IsPhraseLayer​(nzilbb.ag.Layer layer,
                                            nzilbb.ag.Schema schema)
        Determines whether the given layer is a 'phrase' layer.
        Parameters:
        layer - The layer to test.
        schema - The schema the layer comes from.
        Returns:
        true if the given layer is the turn layer or a non-word child of it.
      • IsSpanLayer

        public static boolean IsSpanLayer​(nzilbb.ag.Layer layer,
                                          nzilbb.ag.Schema schema)
        Determines whether the given layer is a 'span' layer.
        Parameters:
        layer - The layer to test.
        schema - The schema the layer comes from.
        Returns:
        true if the given layer is an aligned top-level layer - i.e. parent is root.