List of usage examples for org.apache.lucene.util BytesRefBuilder BytesRefBuilder
public BytesRefBuilder()
From source file:com.github.flaxsearch.util.BytesRefUtils.java
License:Apache License
private static Function<String, BytesRef> getDecoder(String type) { switch (type.toLowerCase(Locale.ROOT)) { case "base64": return s -> new BytesRef(Base64.getUrlDecoder().decode(s.getBytes(Charset.defaultCharset()))); case "utf8": return BytesRef::new; case "int": return s -> { BytesRefBuilder builder = new BytesRefBuilder(); LegacyNumericUtils.intToPrefixCoded(Integer.parseInt(s), 0, builder); return builder.get(); };/*from w w w.j a v a 2 s .c o m*/ case "long": return s -> { BytesRefBuilder builder = new BytesRefBuilder(); LegacyNumericUtils.longToPrefixCoded(Long.parseLong(s), 0, builder); return builder.get(); }; case "float": return s -> { BytesRefBuilder builder = new BytesRefBuilder(); LegacyNumericUtils.intToPrefixCoded(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, builder); return builder.get(); }; case "double": return s -> { BytesRefBuilder builder = new BytesRefBuilder(); LegacyNumericUtils.longToPrefixCoded(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, builder); return builder.get(); }; default: throw new IllegalArgumentException("Unknown decoder type: " + type); } }
From source file:com.google.gerrit.lucene.QueryBuilder.java
License:Apache License
private static Term intTerm(String name, int value) { BytesRefBuilder builder = new BytesRefBuilder(); NumericUtils.intToPrefixCodedBytes(value, 0, builder); return new Term(name, builder.get()); }
From source file:com.meizu.nlp.classification.BooleanPerceptronClassifier.java
License:Apache License
private void updateFST(SortedMap<String, Double> weights) throws IOException { PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton(); Builder<Long> fstBuilder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs); BytesRefBuilder scratchBytes = new BytesRefBuilder(); IntsRefBuilder scratchInts = new IntsRefBuilder(); for (Map.Entry<String, Double> entry : weights.entrySet()) { scratchBytes.copyChars(entry.getKey()); fstBuilder.add(Util.toIntsRef(scratchBytes.get(), scratchInts), entry.getValue().longValue()); }//from w ww . j a v a 2s . com fst = fstBuilder.finish(); }
From source file:com.meltwater.elasticsearch.search.suggest.PrefixSuggester.java
License:Apache License
private List<Term> queryTerms(SuggestionSearchContext.SuggestionContext suggestion, CharsRefBuilder spare) throws IOException { final String field = suggestion.getField(); final List<Term> ret = new ArrayList<Term>(); SuggestUtils.analyze(suggestion.getAnalyzer(), suggestion.getText(), field, new SuggestUtils.TokenConsumer() { @Override/* w w w . j a v a2 s.co m*/ public void nextToken() { ret.add(new Term(field, BytesRef.deepCopyOf(fillBytesRef(new BytesRefBuilder())))); } }, spare); return ret; }
From source file:com.querydsl.lucene5.LuceneSerializer.java
License:Apache License
private BytesRef convertNumber(Number number) { if (Integer.class.isInstance(number) || Byte.class.isInstance(number) || Short.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(number.intValue(), 0, ref); return ref.get(); } else if (Double.class.isInstance(number) || BigDecimal.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); long l = NumericUtils.doubleToSortableLong(number.doubleValue()); NumericUtils.longToPrefixCoded(l, 0, ref); return ref.get(); } else if (Long.class.isInstance(number) || BigInteger.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(number.longValue(), 0, ref); return ref.get(); } else if (Float.class.isInstance(number)) { BytesRefBuilder ref = new BytesRefBuilder(); int i = NumericUtils.floatToSortableInt(number.floatValue()); NumericUtils.intToPrefixCoded(i, 0, ref); return ref.get(); } else {/*from w w w.j a v a 2 s .co m*/ throw new IllegalArgumentException("Unsupported numeric type " + number.getClass().getName()); } }
From source file:com.qwazr.search.index.BytesRefUtils.java
License:Apache License
final static public BytesRef from(final Integer value) { if (value == null) return new BytesRef(BytesRef.EMPTY_BYTES); final BytesRefBuilder builder = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(value, 0, builder); return builder.toBytesRef(); }
From source file:com.qwazr.search.index.BytesRefUtils.java
License:Apache License
final static public BytesRef from(final Long value) { if (value == null) return new BytesRef(BytesRef.EMPTY_BYTES); final BytesRefBuilder builder = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(value, 0, builder); return builder.toBytesRef(); }
From source file:com.qwazr.search.index.BytesRefUtils.java
License:Apache License
final static public BytesRef from(final Float value) { if (value == null) return new BytesRef(BytesRef.EMPTY_BYTES); final BytesRefBuilder builder = new BytesRefBuilder(); NumericUtils.intToPrefixCoded(NumericUtils.floatToSortableInt(value), 0, builder); return builder.toBytesRef(); }
From source file:com.qwazr.search.index.BytesRefUtils.java
License:Apache License
final static public BytesRef from(final Double value) { if (value == null) return new BytesRef(BytesRef.EMPTY_BYTES); final BytesRefBuilder builder = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(NumericUtils.doubleToSortableLong(value), 0, builder); return builder.toBytesRef(); }
From source file:com.stratio.cassandra.lucene.key.TokenMapper.java
License:Apache License
/** * Returns the {@link BytesRef} indexing value of the specified Murmur3 partitioning {@link Token}. * * @param token a Murmur3 token//from w w w . j a v a 2 s . co m * @return the {@code token}'s indexing value */ private static BytesRef bytesRef(Token token) { Long value = value(token); BytesRefBuilder bytesRef = new BytesRefBuilder(); NumericUtils.longToPrefixCoded(value, 0, bytesRef); return bytesRef.get(); }