当前位置: 首页>>代码示例>>Java>>正文


Java SearchException类代码示例

本文整理汇总了Java中com.threewks.gaetools.search.SearchException的典型用法代码示例。如果您正苦于以下问题:Java SearchException类的具体用法?Java SearchException怎么用?Java SearchException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SearchException类属于com.threewks.gaetools.search包,在下文中一共展示了SearchException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertQueryComponentToQueryFragment

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
protected String convertQueryComponentToQueryFragment(QueryComponent queryComponent) {
    if (!queryComponent.isFieldedQuery()) {
        return queryComponent.getQuery();
    }

    String field = this.getEncodedFieldName(queryComponent.getField());
    if (field == null) {
        throw new SearchException("Unable to build query string - there is no field named '%s' on %s", queryComponent.getField(), type.getSimpleName());
    }
    String operation = IsSymbols.get(queryComponent.getIs());
    if (queryComponent.isCollectionQuery()) {
        List<String> values = convertValuesToString(field, queryComponent.getCollectionValue());
        String stringValue = StringUtils.join(values, " OR ");
        return String.format("%s:(%s)", field, stringValue);
    } else {
        String value = convertValueToString(field, queryComponent.getValue());
        return String.format("%s%s%s", field, operation, value);
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:20,代码来源:BaseGaeSearchService.java

示例2: inferIndexType

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
/**
 * Given a type, infer the {@link IndexType} that is used to store and query a field.
 *
 * @param type
 * @return
 */
protected IndexType inferIndexType(Type type) {
    // we go a direct get first
    IndexType indexType = indexTypeMappingCache.get(type);
    if (indexType == null) {
        if (TypeIntrospector.isACollection(type)) {
            type = TypeIntrospector.getCollectionType(type);
        }
        Class<?> classType = TypeIntrospector.asClass(type);
        // if not present, we find the first match in the cache
        for (Map.Entry<Class<?>, IndexType> entry : indexTypeMappingCache.entrySet()) {
            if (entry.getKey().isAssignableFrom(classType)) {
                indexType = entry.getValue();
                // put the matching type back into the cache to speed up subsequent inference
                indexTypeMappingCache.put(classType, indexType);
                break;
            }
        }
    }
    if (indexType == null) {
        throw new SearchException("Unable to infer an %s for the type %s - you should add a mapping using the %s", IndexTypeLookup.class.getSimpleName(), type,
                IndexTypeLookup.class.getSimpleName());
    }
    return indexType;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:31,代码来源:IndexTypeLookup.java

示例3: buildDocument

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
protected Document buildDocument(K id, Map<String, Object> fields) {
    String stringId = convert(id, String.class);
    Builder documentBuilder = Document.newBuilder();
    documentBuilder.setId(stringId);
    for (Map.Entry<String, Object> fieldData : fields.entrySet()) {
        Object value = fieldData.getValue();
        String fieldName = fieldData.getKey();
        for (Object object : getCollectionValues(value)) {
            try {
                Field field = buildField(metadata, fieldName, object);
                documentBuilder.addField(field);
            } catch (Exception e) {
                throw new SearchException(e, "Failed to add field '%s' with value '%s' to document with id '%s': %s", fieldName, value.toString(), id, e.getMessage());
            }
        }
    }

    return documentBuilder.build();
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:20,代码来源:BaseGaeSearchService.java

示例4: SearchMetadata

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
public SearchMetadata(Class<T> type, IndexTypeLookup indexTypeLookup) {
    this.indexTypeLookup = indexTypeLookup;
    this.type = type;
    findMethodAccessors(type);
    findFieldAccessors(type);
    if (idAccessor == null) {
        throw new SearchException("No id found for %s - make sure @%s is on one field or method", type.getSimpleName(), SearchId.class.getSimpleName());
    }
    this.keyType = idAccessor.getType();
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:11,代码来源:SearchMetadata.java

示例5: getIndexType

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
public IndexType getIndexType(String field) {
    Accessor<T, ?> accessor = accessors.get(field);
    if (accessor == null) {
        throw new SearchException("There is no field or getter marked with @%s for %s.%s - make sure it is indexed and accessible", SearchIndex.class.getSimpleName(), type.getSimpleName(), field);
    }
    return accessor.getIndexType();
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:8,代码来源:SearchMetadata.java

示例6: encodeFieldName

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
/**
 * Ensure the field name matches the requirements of the search interface
 *
 * @param fieldName
 * @return
 */
protected String encodeFieldName(String fieldName) {
    // From the docs - They must start with a letter and can contain letters, digits, or underscore
    String encoded = fieldName.replaceAll("[^\\w-]", "-");
    encoded = encoded.replaceAll("-+", "-");
    encoded = encoded.replaceAll("[^a-zA-Z]*([a-zA-Z]+)([\\w-]*)", "$1$2");
    if (!FieldNamePattern.matcher(encoded).matches()) {
        throw new SearchException(
                "The field name '%s' cannot be used - it could not be encoded into an acceptable representation for the text search api. Make sure it has at least one letter. The encoded result was '%s'",
                fieldName, encoded);
    }
    return encoded;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:19,代码来源:SearchMetadata.java

示例7: MethodAccessor

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public MethodAccessor(Class<T> type, Method method, String name, String encodedName, IndexType indexType) {
    try {
        this.type = type;
        this.method = method;
        this.method.setAccessible(true);
        this.methodType = (Class<V>) this.method.getReturnType();
        this.name = name;
        this.encodedName = encodedName;
        this.methodName = method.getName();
        this.indexType = indexType;
    } catch (SecurityException e) {
        throw new SearchException(e, "Unable to access method '%s.%s': %s", type.getSimpleName(), methodName, e.getMessage());
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:16,代码来源:MethodAccessor.java

示例8: get

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public V get(T t) {
    try {
        return (V) method.invoke(t);
    } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
        throw new SearchException(e, "Failed to call method '%s.%s': %s", type.getSimpleName(), methodName, e.getMessage());
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:10,代码来源:MethodAccessor.java

示例9: FieldAccessor

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public FieldAccessor(Class<T> type, Field field, String name, String encodedName, IndexType indexType) {
    try {
        this.type = type;
        this.field = field;
        this.field.setAccessible(true);
        this.fieldType = (Class<V>) this.field.getType();
        this.name = name;
        this.encodedName = encodedName;
        this.fieldName = field.getName();
        this.indexType = indexType;
    } catch (SecurityException e) {
        throw new SearchException(e, "Unable to access field '%s.%s': %s", type.getSimpleName(), fieldName, e.getMessage());
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:16,代码来源:FieldAccessor.java

示例10: get

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public V get(T t) {
    try {
        return (V) field.get(t);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        throw new SearchException(e, "Failed to access field '%s.%s': %s", type.getSimpleName(), fieldName, e.getMessage());
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:10,代码来源:FieldAccessor.java

示例11: results

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
private Results<ScoredDocument> results() {
    if (results == null) {
        try {
            results = searchAsync.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new SearchException(e, "Failed to retrieve search results: %s", e.getMessage());
        }
    }
    return results;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:11,代码来源:ResultImpl.java

示例12: convertSingleValueToString

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
private <V> String convertSingleValueToString(String field, Object value, SearchMetadata<T, ?> metadata, FieldMediator<V> fieldMediator) {
    try {
        V normalised = fieldMediator.normalise(transformerManager, value);
        return fieldMediator.stringify(normalised);
    } catch (Exception e) {
        throw new SearchException("Cannot query the field %s %s - cannot convert the query value %s %s to a %s. You can register extra conversions using the %s", metadata.getFieldType(field)
                .getSimpleName(), field, value.getClass().getSimpleName(), value, fieldMediator.getTargetType().getSimpleName(), TransformerManager.class.getSimpleName());
    }
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:10,代码来源:BaseGaeSearchService.java

示例13: get

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> FieldMediator<T> get(IndexType indexType) {
    FieldMediator<T> result = (FieldMediator<T>) fieldMediators.get(indexType);
    if (result == null) {
        throw new SearchException("No %s present for %s '%s'", FieldMediator.class.getSimpleName(), IndexType.class.getSimpleName(), indexType);
    }
    return result;
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:9,代码来源:FieldMediatorSet.java

示例14: createSearchResult

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@Override
public com.threewks.gaetools.search.Result<E, K> createSearchResult(SearchImpl<E, K> searchRequest) {
    Search<E, Key<E>> delegate = searchRequest.getSearchRequest();
    final com.threewks.gaetools.search.Result<E, Key<E>> delegateResults = delegate.run();
    return new com.threewks.gaetools.search.Result<E, K>() {
        @Override
        public List<E> getResults() throws SearchException {
            return loadInternal(delegateResults.getResultIds());
        }

        @Override
        public List<K> getResultIds() throws SearchException {
            return fromKeys.from(delegateResults.getResultIds());
        }

        @Override
        public long getMatchingRecordCount() {
            return delegateResults.getMatchingRecordCount();
        }

        @Override
        public long getReturnedRecordCount() {
            return delegateResults.getReturnedRecordCount();
        }

        @Override
        public String cursor() {
            return delegateResults.cursor();
        }

    };
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:33,代码来源:AbstractRepository.java

示例15: shouldThrowSearchExceptionWhenCannotGetFieldValue

import com.threewks.gaetools.search.SearchException; //导入依赖的package包/类
@Test
public void shouldThrowSearchExceptionWhenCannotGetFieldValue() throws NoSuchFieldException {
    thrown.expect(SearchException.class);
    thrown.expectMessage("Failed to access field 'FieldAccessorTest.field': ");

    Field field = FieldPojo.class.getDeclaredField("field");

    FieldAccessor<FieldAccessorTest, String> fieldAccessor = new FieldAccessor<>(FieldAccessorTest.class, field, "encoded-name", "notAField", IndexType.Text);
    fieldAccessor.get(this);
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:11,代码来源:FieldAccessorTest.java


注:本文中的com.threewks.gaetools.search.SearchException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。