List of usage examples for org.apache.lucene.util BytesRef EMPTY_BYTES
null EMPTY_BYTES
To view the source code for org.apache.lucene.util BytesRef EMPTY_BYTES.
Click Source Link
From source file:com.qwazr.search.index.BytesRefUtils.java
License:Apache License
final static public BytesRef from(final String value) { if (value == null) return new BytesRef(BytesRef.EMPTY_BYTES); return new BytesRef(value); }
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.qwazr.search.index.BytesRefUtils.java
License:Apache License
final static public BytesRef fromAny(final Object value) { if (value == null) return new BytesRef(BytesRef.EMPTY_BYTES); if (value instanceof String) return from((String) value); if (value instanceof Integer) return from((Integer) value); if (value instanceof Float) return from((Float) value); if (value instanceof Long) return from((String) value); if (value instanceof Double) return from((String) value); if (value instanceof BytesRef) return (BytesRef) value; return new BytesRef(value.toString()); }
From source file:cz.muni.fi.mias.PayloadSimilarity.java
License:Apache License
@Override public float scorePayload(int docId, int start, int end, BytesRef byteRef) { float score = 1.0F; if (byteRef.bytes != BytesRef.EMPTY_BYTES) { score = PayloadHelper.decodeFloatFromShortBytes(byteRef.bytes); }//from w w w . jav a 2 s .c o m return score; }
From source file:edu.upenn.library.solrplugins.CaseInsensitiveSortingTextField.java
License:Apache License
@Override public BytesRef normalizeQueryTarget(String val, boolean strict, String fieldName, boolean appendExtraDelim) throws IOException { TokenStream ts = getQueryAnalyzer().tokenStream(fieldName, val); try {/* w w w . j a v a 2 s.c o m*/ ts.reset(); CharTermAttribute termAtt = ts.getAttribute(CharTermAttribute.class); TypeAttribute typeAtt = ts.getAttribute(TypeAttribute.class); String matchType = strict ? INDEXED_TOKEN_TYPE : NORMALIZED_TOKEN_TYPE; while (ts.incrementToken()) { if (matchType.equals(typeAtt.type())) { BytesRefBuilder ret = new BytesRefBuilder(); ret.copyChars(termAtt.toString()); if (!strict || appendExtraDelim) { ret.append(delimBytes, 0, delimBytes.length); } return ret.get(); } } return new BytesRef(BytesRef.EMPTY_BYTES); } finally { ts.close(); } }
From source file:org.elasticsearch.benchmark.transport.BenchmarkNettyLargeMessages.java
License:Apache License
public static void main(String[] args) throws InterruptedException { final ByteSizeValue payloadSize = new ByteSizeValue(10, ByteSizeUnit.MB); final int NUMBER_OF_ITERATIONS = 100000; final int NUMBER_OF_CLIENTS = 5; final byte[] payload = new byte[(int) payloadSize.bytes()]; Settings settings = ImmutableSettings.settingsBuilder().build(); NetworkService networkService = new NetworkService(settings); final ThreadPool threadPool = new ThreadPool(); final TransportService transportServiceServer = new TransportService( new NettyTransport(settings, threadPool, networkService, Version.CURRENT), threadPool).start(); final TransportService transportServiceClient = new TransportService( new NettyTransport(settings, threadPool, networkService, Version.CURRENT), threadPool).start(); final DiscoveryNode bigNode = new DiscoveryNode("big", new InetSocketTransportAddress("localhost", 9300), Version.CURRENT);//from w w w .ja v a 2 s. c o m // final DiscoveryNode smallNode = new DiscoveryNode("small", new InetSocketTransportAddress("localhost", 9300)); final DiscoveryNode smallNode = bigNode; transportServiceClient.connectToNode(bigNode); transportServiceClient.connectToNode(smallNode); transportServiceServer.registerHandler("benchmark", new BaseTransportRequestHandler<BenchmarkMessageRequest>() { @Override public BenchmarkMessageRequest newInstance() { return new BenchmarkMessageRequest(); } @Override public String executor() { return ThreadPool.Names.GENERIC; } @Override public void messageReceived(BenchmarkMessageRequest request, TransportChannel channel) throws Exception { channel.sendResponse(new BenchmarkMessageResponse(request)); } }); final CountDownLatch latch = new CountDownLatch(NUMBER_OF_CLIENTS); for (int i = 0; i < NUMBER_OF_CLIENTS; i++) { new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { BenchmarkMessageRequest message = new BenchmarkMessageRequest(1, payload); transportServiceClient.submitRequest(bigNode, "benchmark", message, options().withType(TransportRequestOptions.Type.BULK), new BaseTransportResponseHandler<BenchmarkMessageResponse>() { @Override public BenchmarkMessageResponse newInstance() { return new BenchmarkMessageResponse(); } @Override public String executor() { return ThreadPool.Names.SAME; } @Override public void handleResponse(BenchmarkMessageResponse response) { } @Override public void handleException(TransportException exp) { exp.printStackTrace(); } }).txGet(); } latch.countDown(); } }).start(); } new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < 1; i++) { BenchmarkMessageRequest message = new BenchmarkMessageRequest(2, BytesRef.EMPTY_BYTES); long start = System.currentTimeMillis(); transportServiceClient.submitRequest(smallNode, "benchmark", message, options().withType(TransportRequestOptions.Type.STATE), new BaseTransportResponseHandler<BenchmarkMessageResponse>() { @Override public BenchmarkMessageResponse newInstance() { return new BenchmarkMessageResponse(); } @Override public String executor() { return ThreadPool.Names.SAME; } @Override public void handleResponse(BenchmarkMessageResponse response) { } @Override public void handleException(TransportException exp) { exp.printStackTrace(); } }).txGet(); long took = System.currentTimeMillis() - start; System.out.println("Took " + took + "ms"); } } }).start(); latch.await(); }
From source file:org.elasticsearch.common.bytes.AbstractBytesReferenceTestCase.java
License:Apache License
public void testHashCode() throws IOException { // empty content must have hash 1 (JDK compat) BytesReference pbr = newBytesReference(0); assertEquals(Arrays.hashCode(BytesRef.EMPTY_BYTES), pbr.hashCode()); // test with content pbr = newBytesReference(randomIntBetween(0, PAGE_SIZE * randomIntBetween(2, 5))); int jdkHash = Arrays.hashCode(BytesReference.toBytes(pbr)); int pbrHash = pbr.hashCode(); assertEquals(jdkHash, pbrHash);/*from ww w.j a v a 2 s . com*/ // test hashes of slices int sliceFrom = randomIntBetween(0, pbr.length()); int sliceLength = randomIntBetween(0, pbr.length() - sliceFrom); BytesReference slice = pbr.slice(sliceFrom, sliceLength); int sliceJdkHash = Arrays.hashCode(BytesReference.toBytes(slice)); int sliceHash = slice.hashCode(); assertEquals(sliceJdkHash, sliceHash); }