src/snac/server/database/SQL.php
/**
     * Search Vocabulary
     *
     * This method allows searching the vocabulary table for a given type and value
     *
     * Any term which is a key in $useStartsWith will use a "starts with" type of ilike match. That is, the
     * $query must be at the beginning of the search. The default is for $query to occur anywhere.
     *
     * Add new terms as keys in $useStartsWith as necessary. The choice of value 1 is not arbitrary, and works
     * well in most situations where a hash aka associative list is being used in a control statement.
     *
     * @param string $term The "type" term for what type of vocabulary to search
     * @param string $query The string to search through the vocabulary
     * @param integer $entityTypeID Numeric key related to vocabulary.id where type='entity_type' of one of
     * the three entity types.
     * @param int $count optional The number of search results to request
     * @return string[][] Returns a list of lists with keys id, value.
     */
Search Vocabulary
This method allows searching the vocabulary table for a given type and value

Any term which is a key in $useStartsWith will use a "starts with" type of ilike match. That is, the
$query must be at the beginning of the search. The default is for $query to occur anywhere.

Add new terms as keys in $useStartsWith as necessary. The choice of value 1 is not arbitrary, and works
well in most situations where a hash aka associative list is being used in a control statement.

@param string $term The "type" term for what type of vocabulary to search
@param string $query The string to search through the vocabulary
@param integer $entityTypeID Numeric key related to vocabulary.id where type='entity_type' of one of
the three entity types.
@param int $count optional The number of search results to request
@return string[][] Returns a list of lists with keys id, value.
Search Vocabulary This method allows searching the vocabulary table for a given type and value Any term which is a key in $useStartsWith will use a " starts with " type of ilike match . That is the $query must be at the beginning of the search . The default is for $query to occur anywhere . Add new terms as keys in $useStartsWith as necessary . The choice of value 1 is not arbitrary and works well in most situations where a hash aka associative list is being used in a control statement . @param string $term The " type " term for what type of vocabulary to search @param string $query The string to search through the vocabulary @param integer $entityTypeID Numeric key related to vocabulary . id where type = ' entity_type ' of one of the three entity types . @param int $count optional The number of search results to request @return string [] [] Returns a list of lists with keys id value .
public function searchVocabulary($term, $query, $entityTypeID, $count = 100)
    {
        $useStartsWith = array('script_code' => 1,
                               'language_code' => 1,
                               'gender' => 1,
                               'nationality' => 1,
                               'subject' => 1,
                               'activity' => 1,
                               'occupation' => 1);
        $likeStr = "%$query%";
        if (isset($useStartsWith[$term]))
        {
            $likeStr = "$query%";
        }
        if ($entityTypeID == null)
        {
            $queryStr =
                      'select id,value,type,uri,description
                      from vocabulary
                      where type=$1 and value ilike $2 order by value asc limit $3';
            $result = $this->sdb->query($queryStr, array($term, $likeStr, $count));
        }
        else
        {
            $queryStr =
                      'select id,value
                      from vocabulary
                      where type=$1 and value ilike $2 and (entity_group=$3 or entity_group is null) order by value asc limit 100';
            $result = $this->sdb->query($queryStr, array($term, $likeStr, $entityTypeID));
        }
        $all = array();
        while($row = $this->sdb->fetchrow($result))
        {
            array_push($all, $row);
        }
        return $all;
    }
public function searchVocabulary ( $ term , $ query , $ entityTypeID , $ count = 100 ) { $ useStartsWith = array ( 'script_code' => 1 , 'language_code' => 1 , 'gender' => 1 , 'nationality' => 1 , 'subject' => 1 , 'activity' => 1 , 'occupation' => 1 ) ; $ likeStr = " % $ query % " ; if ( isset ( $ useStartsWith [ $ term ] ) ) { $ likeStr = " $ query % " ; } if ( $ entityTypeID == null ) { $ queryStr = 'select id,value,type,uri,description
                      from vocabulary
                      where type=$1 and value ilike $2 order by value asc limit $3' ; $ result = $ this -> sdb -> query ( $ queryStr , array ( $ term , $ likeStr , $ count ) ) ; } else { $ queryStr = 'select id,value
                      from vocabulary
                      where type=$1 and value ilike $2 and (entity_group=$3 or entity_group is null) order by value asc limit 100' ; $ result = $ this -> sdb -> query ( $ queryStr , array ( $ term , $ likeStr , $ entityTypeID ) ) ; } $ all = array ( ) ; while ( $ row = $ this -> sdb -> fetchrow ( $ result ) ) { array_push ( $ all , $ row ) ; } return $ all ; }
Search Vocabulary
 This method allows searching the vocabulary table for a given type and value
Search Vocabulary This method allows searching the vocabulary table for a given type and value
/*
         * $this->enableLogging();
         * $this->logDebug("sql.php term: $term likeStr: $likeStr", array());
         */ /*
             * If we have a non-null entityTypeID then the type should be 'name_component'. We could check
             * that although it isn't really necessary. When called with some other type, no records will be
             * returned, presumably because the only values using entity_group are type='name_component'.
             *
             * The values for type name_component are at the end of the file install/sql_files/vocabulary.sql.
             *
             * We need an "or" clause because NameAddition and Date are used for multiple name
             * components. Ideally, NameAddition is person and corporateBody and not family, but to simplify
             * things we say null is all three for NameAddition and Date.
             *
             * If null becomes a problem, zero or some other integer that is not an entity type would probably
             * work just as well. Better perhaps since nulls preclude using entity_group in a primary key.
             *
             * It might be better to return these ordered by id instead of value. The UI may have expectations
             * about the order.
             */ /* Disable sorting name components, for now.
         * if ($term == 'name_component' && count($all) > 1)
         * {
         *     return $this->specialSort($all);
         * }
         */