@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof DocumentState)) return false; DocumentState that = (DocumentState) o; if (removeEntry != that.removeEntry) return false; if (timestamp != that.timestamp) return false; if (docId != null ? !docId.equals(that.docId) : that.docId != null) return false; return gid.equals(that.gid); }
@Override public int hashCode() { return globalId.hashCode() + 10 * partid + strHashCode(summaryClass); }
public DocumentState(DocumentId docId, long timestamp, boolean removeEntry) { this.docId = docId; this.gid = new GlobalId(docId.getGlobalId()); this.timestamp = timestamp; this.removeEntry = removeEntry; }
private static StringBuilder asHexString(StringBuilder sb, GlobalId gid) { byte[] rawGid = gid.getRawId(); for (byte b : rawGid) { String hex = Integer.toHexString(0xFF & b); if (hex.length() == 1) { sb.append('0'); } sb.append(hex); } return sb; }
public String toString() { return "docsum packet [globalId: " + globalId.toString() + ", size: " + (data==null ? "(no data)" : data.length + " bytes") + " ]"; }
@Override public int compareTo(DocumentState state) { int comp = gid.compareTo(state.gid); if (comp == 0) { if (docId != null) { if (state.docId != null) { return docId.toString().compareTo(state.docId.toString()); } else { return 1; } } else if (state.docId != null){ return -1; } } return comp; }
public void serialize(Serializer buf) { if (docId != null) { buf.putByte(null, (byte) 1); docId.serialize(buf); } else { buf.putByte(null, (byte) 0); } gid.serialize(buf); buf.putLong(null, timestamp); buf.putByte(null, (byte)(removeEntry ? 1 : 0)); }
/** * Fills this packet from a byte buffer positioned at the * first byte of the packet */ public void decodeBody(ByteBuffer buffer) { byte[] rawGid = new byte[GlobalId.LENGTH]; buffer.get(rawGid); globalId = new GlobalId(rawGid); data=new byte[getLength()-12-GlobalId.LENGTH]; buffer.get(data); }
private void encodeDocIds(ByteBuffer buffer) { byte[] emptyGid = new byte[GlobalId.LENGTH]; for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext(); ) { Hit hit = i.next(); if (hit instanceof FastHit && !hit.isFilled(summaryClass)) { FastHit fastHit = (FastHit)hit; buffer.put(fastHit.getGlobalId() != null ? fastHit.getGlobalId().getRawId() : emptyGid); buffer.putInt(fastHit.getPartId()); buffer.putInt(0); //Unused, was docstamp } } }
DocumentInfo(ByteBuffer buffer, QueryResultPacket owner) { byte[] rawGid = new byte[GlobalId.LENGTH]; buffer.get(rawGid); globalId = new GlobalId(rawGid); metric = decodeMetric(buffer); partId = owner.getMldFeature() ? buffer.getInt() : 0; distributionKey = owner.getMldFeature() ? buffer.getInt() : 0; }
@Override public boolean equals(Object o) { if (o instanceof DocsumPacketKey) { DocsumPacketKey other = (DocsumPacketKey) o; if (globalId.equals(other.getGlobalId()) && partid == other.getPartid() && strEquals(summaryClass, other.summaryClass)) { return true; } } return false; }
static private Slime toSlime(String rankProfile, String summaryClass, String docType, SessionId sessionId, List<FastHit> hits) { Slime slime = new Slime(); Cursor root = slime.setObject(); if (summaryClass != null) { root.setString("class", summaryClass); } if (sessionId != null) { root.setData("sessionid", sessionId.asUtf8String().getBytes()); } if (docType != null) { root.setString("doctype", docType); } if (rankProfile != null) { root.setString("ranking", rankProfile); } Cursor gids = root.setArray("gids"); for (FastHit hit : hits) { gids.addData(hit.getGlobalId().getRawId()); } return slime; }
@Override public int hashCode() { int result; result = (docId != null ? docId.hashCode() : 0); result = 31 * result + gid.hashCode(); result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); result = 31 * result + (removeEntry ? 1 : 0); return result; }
/** * Only used by PacketCacheTestCase, should not be used otherwise */ public PacketWrapper(CacheKey key, BasicPacket[] packets) { // Should support key == null as this is for testing if (key == null) { keySize = 0; } else { this.keySize = key.byteSize(); } resultPackets.add(packets[0]); this.packets = new LinkedHashMap<>(); this.distributionKey = Optional.empty(); for (int i = 0; i < packets.length - 1; i++) { this.packets.put(new DocsumPacketKey(new GlobalId(new DocumentId("doc:test:" + i).getGlobalId()), i, null), packets[i + 1]); } }
public void addDocsums(DocsumPacketKey[] packetKeys, Packet[] packets) { if (packetKeys == null || packets == null) { log.warning( "addDocsums called with " + (packetKeys == null ? "packetKeys == null " : "") + (packets == null ? "packets == null" : "")); return; } for (int i = 0; i < packetKeys.length && i < packets.length; i++) { if (packetKeys[i] == null) { log.warning( "addDocsums called, but packetsKeys[" + i + "] is null"); } else if (packets[i] instanceof DocsumPacket) { DocsumPacket dp = (DocsumPacket) packets[i]; if (packetKeys[i].getGlobalId().equals(dp.getGlobalId()) && dp.getData().length > 0) { this.packets.put(packetKeys[i], packets[i]); log.fine("addDocsums " + i + " globalId: " + dp.getGlobalId()); } else { log.warning("not caching bad Docsum for globalId " + packetKeys[i].getGlobalId() + ": " + dp); } } else { log.warning( "addDocsums called, but packets[" + i + "] is not a DocsumPacket instance"); } } }
public DocumentState(Deserializer buf) { byte hasDocId = buf.getByte(null); if (hasDocId == (byte) 1) { docId = new DocumentId(buf); } gid = new GlobalId(buf); timestamp = buf.getLong(null); removeEntry = buf.getByte(null)>0; }