Search in sources :

Example 21 with Index

use of org.folio.dbschema.Index in project raml-module-builder by folio-org.

the class CQL2PgJSON method queryByFt.

/**
 * Create an SQL expression using Full Text query syntax.
 *
 * @param hasIndex
 * @param vals
 * @param node
 * @param comparator
 * @param modifiers
 * @return
 * @throws QueryValidationException
 */
private String queryByFt(String index, DbIndex dbIndex, IndexTextAndJsonValues vals, CQLTermNode node, String comparator, CqlModifiers modifiers, Table targetTable) throws QueryValidationException {
    final String indexText = vals.getIndexText();
    if (CqlAccents.RESPECT_ACCENTS == modifiers.getCqlAccents()) {
        logger.log(Level.WARNING, "Ignoring /respectAccents modifier for FT search {0}", indexText);
    }
    if (CqlCase.RESPECT_CASE == modifiers.getCqlCase()) {
        logger.log(Level.WARNING, "Ignoring /respectCase modifier for FT search {0}", indexText);
    }
    // Clean the term. Remove stand-alone ' *', not valid word.
    String term = node.getTerm().replaceAll(" +\\*", "").trim();
    Index schemaIndex = null;
    if (targetTable != null) {
        schemaIndex = DbSchemaUtils.getIndex(index, targetTable.getFullTextIndex());
    }
    String sql = queryByFt(indexText, term, comparator, schemaIndex, targetTable);
    // array modifier
    List<Modifier> relationModifiers = modifiers.getRelationModifiers();
    if (!relationModifiers.isEmpty()) {
        sql += " AND " + arrayNode(index, node, modifiers, relationModifiers, schemaIndex, vals, targetTable);
    }
    if (schemaIndex != null && schemaIndex.isCaseSensitive()) {
        throw new CQLFeatureUnsupportedException("full text index does not support case sensitive: " + index);
    }
    if (!dbIndex.hasFullTextIndex() && !"true".equals(sql)) {
        String s = String.format("%s, CQL >>> SQL: %s >>> %s", indexText, node.toCQL(), sql);
        logger.log(Level.WARNING, "Doing FT search without index for {0}", s);
    }
    return sql;
}
Also used : DbIndex(org.folio.cql2pgjson.model.DbIndex) Index(org.folio.dbschema.Index) Modifier(org.z3950.zing.cql.Modifier) CQLFeatureUnsupportedException(org.folio.cql2pgjson.exception.CQLFeatureUnsupportedException)

Example 22 with Index

use of org.folio.dbschema.Index in project raml-module-builder by folio-org.

the class DbSchemaUtilsTest method newIndex.

private static Index newIndex(String name) {
    Index index = new Index();
    index.setFieldName(name);
    return index;
}
Also used : DbIndex(org.folio.cql2pgjson.model.DbIndex) Index(org.folio.dbschema.Index)

Aggregations

Index (org.folio.dbschema.Index)22 Test (org.junit.jupiter.api.Test)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 DbIndex (org.folio.cql2pgjson.model.DbIndex)5 Modifier (org.z3950.zing.cql.Modifier)3 CQLFeatureUnsupportedException (org.folio.cql2pgjson.exception.CQLFeatureUnsupportedException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Pattern (java.util.regex.Pattern)1 ObjectUtils (org.apache.commons.lang3.ObjectUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 FieldException (org.folio.cql2pgjson.exception.FieldException)1 QueryValidationException (org.folio.cql2pgjson.exception.QueryValidationException)1