List of usage examples for org.apache.lucene.util CharsRefBuilder grow
public void grow(int newLength)
From source file:org.apache.solr.schema.EnumFieldType.java
License:Apache License
@Override public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder output) { final Integer intValue = NumericUtils.sortableBytesToInt(input.bytes, 0); final String stringValue = enumMapping.intValueToStringValue(intValue); output.grow(stringValue.length()); output.setLength(stringValue.length()); stringValue.getChars(0, output.length(), output.chars(), 0); return output.get(); }
From source file:org.apache.solr.schema.PointField.java
License:Apache License
@Override public CharsRef indexedToReadable(BytesRef indexedForm, CharsRefBuilder charsRef) { final String value = indexedToReadable(indexedForm); charsRef.grow(value.length()); charsRef.setLength(value.length());/*from w w w.j a v a 2 s. c om*/ value.getChars(0, charsRef.length(), charsRef.chars(), 0); return charsRef.get(); }
From source file:org.codelibs.elasticsearch.search.suggest.completion.context.ContextMappings.java
License:Apache License
/** * Wraps a {CompletionQuery} with context queries * * @param query base completion query to wrap * @param queryContexts a map of context mapping name and collected query contexts * @return a context-enabled query//from ww w . j a v a 2 s. c o m */ public ContextQuery toContextQuery(CompletionQuery query, Map<String, List<ContextMapping.InternalQueryContext>> queryContexts) { ContextQuery typedContextQuery = new ContextQuery(query); if (queryContexts.isEmpty() == false) { CharsRefBuilder scratch = new CharsRefBuilder(); scratch.grow(1); for (int typeId = 0; typeId < contextMappings.size(); typeId++) { scratch.setCharAt(0, (char) typeId); scratch.setLength(1); ContextMapping mapping = contextMappings.get(typeId); List<ContextMapping.InternalQueryContext> internalQueryContext = queryContexts.get(mapping.name()); if (internalQueryContext != null) { for (ContextMapping.InternalQueryContext context : internalQueryContext) { scratch.append(context.context); typedContextQuery.addContext(scratch.toCharsRef(), context.boost, !context.isPrefix); scratch.setLength(1); } } } } return typedContextQuery; }
From source file:org.elasticsearch.search.suggest.filteredsuggest.filter.FilterMappings.java
License:Apache License
/** * Wraps a {@link CompletionQuery} with context queries * * @param query//from w w w . java 2 s . c o m * base completion query to wrap * @param queryFilters * a map of context mapping name and collected query contexts * @return context-enabled queries */ public List<ContextQuery> toContextQuery(CompletionQuery query, Map<String, List<ContextMapping.InternalQueryContext>> queryFilters) { List<ContextQuery> queries = new ArrayList<>(4); List<ContextMapping.InternalQueryContext> internalQueryContext = queryFilters.get("default_empty"); if (internalQueryContext != null) { ContextQuery typedContextQuery = new ContextQuery(query); CharsRefBuilder scratch = new CharsRefBuilder(); scratch.grow(1); ContextMapping.InternalQueryContext context = internalQueryContext.get(0); scratch.append(context.context); typedContextQuery.addContext(scratch.toCharsRef(), context.boost, !context.isPrefix); queries.add(typedContextQuery); return queries; } if (queryFilters.isEmpty() == false) { CharsRefBuilder scratch = new CharsRefBuilder(); scratch.grow(1); for (String name : queryFilters.keySet()) { internalQueryContext = queryFilters.get(name); if (internalQueryContext != null) { ContextQuery typedContextQuery = new ContextQuery(query); for (ContextMapping.InternalQueryContext context : internalQueryContext) { scratch.append(context.context); typedContextQuery.addContext(scratch.toCharsRef(), context.boost, !context.isPrefix); scratch.setLength(0); } queries.add(typedContextQuery); } } } return queries; }