Java Code Examples for org.alfresco.repo.search.impl.QueryParserUtils

The following examples show how to use org.alfresco.repo.search.impl.QueryParserUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Given the field name, returns the name of the property definition.
 * If the property definition is not found, Empty optional is returned.
 *
 * @param field the field name.
 * @return the name of the associated property definition if present, Optional.Empty() otherwise
 */
static Optional<QName> getShardProperty(String field)
{
    if (StringUtils.isBlank(field))
    {
        throw new IllegalArgumentException("Sharding property " + SHARD_KEY_KEY + " has not been set.");
    }

    AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance();
    NamespaceDAO namespaceDAO = dataModel.getNamespaceDAO();
    DictionaryService dictionaryService = dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT);
    PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition("http://www.alfresco.org/model/content/1.0",
            namespaceDAO,
            dictionaryService,
            field);

    return ofNullable(propertyDef).map(PropertyDefinition::getName);
}
 
Example 2
private PropertyDefinition getPropertyDefinition(String identifier)
{
    return QueryParserUtils.matchPropertyDefinition(NamespaceService.CONTENT_MODEL_1_0_URI,
            getNamespaceDAO(),
            getDictionaryService(CMISStrictDictionaryService.DEFAULT),
            identifier);
}
 
Example 3
protected void buildRangeParameters(SearchParameters searchParameters, URLCodec encoder, StringBuilder url) throws UnsupportedEncodingException
{
    if (searchParameters.getRanges() != null && !searchParameters.getRanges().isEmpty())
    {
        List<RangeParameters> ranges = searchParameters.getRanges();
        url.append("&facet=").append(encoder.encode("true", "UTF-8"));
        
        for(RangeParameters facetRange : ranges)
        {
            String fieldName = facetRange.getField();
            boolean isDate = false;
            PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition(searchParameters.getNamespace(),
                    namespaceDAO, dictionaryService, fieldName);
            if (propertyDef != null && (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME)
                    || propertyDef.getDataType().getName().equals(DataTypeDefinition.DATE)))
            {
                isDate = true;
            }
            
            
            IntervalSet rangeSet =
                    parseDateInterval(
                            new IntervalSet(facetRange.getStart(), 
                                            facetRange.getEnd(), 
                                            facetRange.getGap(), 
                                            null, 
                                            null), isDate);
            url.append("&facet.range=");

            if(facetRange.getLabel()!= null && !facetRange.getLabel().isEmpty())
            {
                url.append(encoder.encode("{!", "UTF-8"));
                url.append(encoder.encode(String.format("tag=%s ",facetRange.getLabel()), "UTF-8"));
                url.append(encoder.encode("}", "UTF-8"));
            }

            url.append(encoder.encode(facetRange.getField(), "UTF-8"));

            //Check if date and if inclusive or not
            url.append(String.format("&f.%s.facet.range.start=",fieldName)).append(encoder.encode(""+ rangeSet.getStart(), "UTF-8"));
            url.append(String.format("&f.%s.facet.range.end=",fieldName)).append(encoder.encode(""+ rangeSet.getEnd(), "UTF-8"));
            url.append(String.format("&f.%s.facet.range.gap=",fieldName)).append(encoder.encode(""+ rangeSet.getLabel(), "UTF-8"));
            url.append(String.format("&f.%s.facet.range.hardend=",fieldName)).append(encoder.encode("" + facetRange.isHardend(), "UTF-8"));
            if(facetRange.getInclude() != null && !facetRange.getInclude().isEmpty())
            {
                for(String include : facetRange.getInclude())
                {
                    url.append(String.format("&f.%s.facet.range.include=",fieldName)).append(encoder.encode("" + include, "UTF-8"));
                }
            }
            if(facetRange.getOther() != null && !facetRange.getOther().isEmpty())
            {
                for(String other : facetRange.getOther())
                {
                    url.append(String.format("&f.%s.facet.range.other=",fieldName)).append(encoder.encode("" + other, "UTF-8"));
                }
            }
            if(!facetRange.getExcludeFilters().isEmpty())
            {
                url.append("&facet.range=");
                if (facetRange.getExcludeFilters() != null && !facetRange.getExcludeFilters().isEmpty())
                {
                    StringBuilder prefix = new StringBuilder("{!ex=");
                    Iterator<String> itr = facetRange.getExcludeFilters().iterator();
                    while(itr.hasNext())
                    {
                        String val = itr.next();
                        prefix.append(val);
                        if(itr.hasNext())
                        {
                            prefix.append(",");
                        }
                    }
                    prefix.append("}");
                    url.append(prefix);
                    url.append(fieldName);
                }
                
            }
        }
    }
}
 
Example 4
/**
    * {@inheritDoc}
    */
public void getNodes(NodeParameters nodeParameters, NodeQueryCallback callback)
{
    if(enabled)
    {
        QName shardPropertQName = null;
        QName shardPropertyType = null;

        if(nodeParameters.getShardProperty() != null)
        {
            PropertyDefinition pdef = QueryParserUtils.matchPropertyDefinition(NamespaceService.CONTENT_MODEL_1_0_URI, namespaceService, dictionaryService, nodeParameters.getShardProperty());
            if(pdef == null)
            {
                logger.warn("Invalid shard property: "+nodeParameters.getShardProperty());
            } else
               {
                   shardPropertyType = pdef.getDataType().getName();

                   if (!shardPropertyType.equals(DataTypeDefinition.TEXT)
                           && !shardPropertyType.equals(DataTypeDefinition.DATE)
                           && !shardPropertyType.equals(DataTypeDefinition.DATETIME)
                           && !shardPropertyType.equals(DataTypeDefinition.INT)
                           && !shardPropertyType.equals(DataTypeDefinition.LONG))
                   {
                       logger.warn("Unsupported shard property type: "+(pdef.getDataType().getName() + " for " +nodeParameters.getShardProperty()));
                   }
                   else
                   {
                       shardPropertQName = pdef.getName();
                   }
               }
        }


        List<Node> nodes = solrDAO.getNodes(nodeParameters, shardPropertQName, shardPropertyType);

        for (Node node : nodes)
        {
               if (shardRegistry != null){
                   shardRegistry.getShardInstanceByTransactionTimestamp(
                           nodeParameters.getCoreName(),
                           node.getTransaction().getCommitTimeMs()).ifPresent(
                                   shardId -> ((NodeEntity) node).setExplicitShardId(shardId));

               }

            callback.handleNode(node);
        }
    }
}
 
Example 5
/**
 *
 * return the stored field associated to potentialProperty parameter
 */
public String mapStoredProperty(String potentialProperty, SolrQueryRequest req)
{
    if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_"))
    {
        return potentialProperty;
    }

    if(potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE"))
    {
        return "score";
    }

    AlfrescoFunctionEvaluationContext functionContext =
        new AlfrescoSolr4FunctionEvaluationContext(
            getNamespaceDAO(),
            getDictionaryService(CMISStrictDictionaryService.DEFAULT),
            NamespaceService.CONTENT_MODEL_1_0_URI,
            req.getSchema());


    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(potentialProperty);
    String luceneField =  functionContext.getLuceneFieldName(fieldNameAndEnding.getFirst());

    PropertyDefinition propertyDef = getPropertyDefinition(fieldNameAndEnding.getFirst());
    //Retry scan using luceneField.
    if(propertyDef == null)
    {
        if(luceneField.contains("@"))
        {
            int index = luceneField.lastIndexOf("@");
            propertyDef = getPropertyDefinition(luceneField.substring(index +1));
        }
    }

    if (propertyDef == null || propertyDef.getName() == null)
    {
        return mapNonPropertyFields(luceneField);
    }

    if (isDateOrDatetime(propertyDef.getDataType()) && isDerivedDateField(fieldNameAndEnding.getSecond()))
    {
        return getDateDerivedField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT))
    {
        return getStoredTextField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))
    {
        return getStoredMLTextField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
    {
        return getStoredContentField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else
    {
        return mapAlfrescoField(FieldUse.FTS, 0, fieldNameAndEnding, luceneField, propertyDef)
                + fieldNameAndEnding.getSecond();
    }
}
 
Example 6
public String  mapProperty(String  potentialProperty,  FieldUse fieldUse, SolrQueryRequest req, int position)
{
    if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_"))
    {
        return potentialProperty;
    }

    if(potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE"))
    {
        return "score";
    }

    if(req.getSchema().getFieldOrNull(potentialProperty) != null)
    {
        return mapNonPropertyFields(potentialProperty);
    }

    AlfrescoFunctionEvaluationContext functionContext =
            new AlfrescoSolr4FunctionEvaluationContext(
                    getNamespaceDAO(),
                    getDictionaryService(CMISStrictDictionaryService.DEFAULT),
                    NamespaceService.CONTENT_MODEL_1_0_URI,
                    req.getSchema());

    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(potentialProperty);
    String luceneField =  functionContext.getLuceneFieldName(fieldNameAndEnding.getFirst());

    PropertyDefinition propertyDef = getPropertyDefinition(fieldNameAndEnding.getFirst());
    //Retry scan using luceneField.
    if(propertyDef == null)
    {
        if(luceneField.contains("@"))
        {
            int index = luceneField.lastIndexOf("@");
            propertyDef = getPropertyDefinition(luceneField.substring(index +1));
        }
    }
    String solrSortField;
    solrSortField = mapAlfrescoField(fieldUse, position, fieldNameAndEnding, luceneField, propertyDef);
    return solrSortField;
}