blob: d7dc2781b5a4345789334a91f938c67305157792 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.query;
import com.yahoo.prelude.query.textualrepresentation.Discloser;
import java.nio.ByteBuffer;
/**
* A word item which only consists of a value and weight, and gets other properties
* such as the index to query from ther parent item.
*
* It's more efficient to use pure items where possible instead of
* {@link TermItem} children ({@link WordItem}, {@link IntItem})
* which may carry many auxiliary properties.
*
* @author baldersheim
*/
public abstract class PureWeightedItem extends Item {
public PureWeightedItem(int weight) {
setWeight(weight);
}
/** Ignored. */
@Override
public void setIndexName(String index) {
// No index
}
@Override
public String getName() {
return getItemType().name();
}
@Override
public int encode(ByteBuffer buffer) {
encodeThis(buffer);
return 1;
}
@Override
protected void appendBodyString(StringBuilder buffer) {
buffer.append(':').append(getWeight());
}
@Override
public void disclose(Discloser discloser) {
discloser.addProperty("weight", getWeight());
}
}
|