public static EncodeFloat ( float payload ) : byte[] | ||
payload | float | |
return | byte[] |
public override Payload Encode(char[] buffer, int offset, int length) { Payload result = new Payload(); float payload = Single.Parse(new string(buffer, offset, length)); // TODO: improve this so that we don't have to new Strings byte[] bytes = PayloadHelper.EncodeFloat(payload); result.SetData(bytes); return(result); }
public override BytesRef Encode(char[] buffer, int offset, int length) { float payload = float.Parse(new string(buffer, offset, length)); //TODO: improve this so that we don't have to new Strings byte[] bytes = PayloadHelper.EncodeFloat(payload); BytesRef result = new BytesRef(bytes); return(result); }
public NumericPayloadTokenFilter(TokenStream input, float payload, String typeMatch) : base(input) { //Need to encode the payload thePayload = new Payload(PayloadHelper.EncodeFloat(payload)); this.typeMatch = typeMatch; payloadAtt = AddAttribute <IPayloadAttribute>(); typeAtt = AddAttribute <ITypeAttribute>(); }
public NumericPayloadTokenFilter(TokenStream input, float payload, string typeMatch) : base(input) { if (typeMatch == null) { throw new System.ArgumentException("typeMatch cannot be null"); } //Need to encode the payload thePayload = new BytesRef(PayloadHelper.EncodeFloat(payload)); this.typeMatch = typeMatch; this.payloadAtt = AddAttribute <IPayloadAttribute>(); this.typeAtt = AddAttribute <ITypeAttribute>(); }
public virtual void TestFloatEncoding() { string test = "The quick|1.0 red|2.0 fox|3.5 jumped|0.5 over the lazy|5 brown|99.3 dogs|83.7"; DelimitedPayloadTokenFilter filter = new DelimitedPayloadTokenFilter(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false), '|', new FloatEncoder()); ICharTermAttribute termAtt = filter.GetAttribute <ICharTermAttribute>(); IPayloadAttribute payAtt = filter.GetAttribute <IPayloadAttribute>(); filter.Reset(); AssertTermEquals("The", filter, termAtt, payAtt, null); AssertTermEquals("quick", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(1.0f)); AssertTermEquals("red", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(2.0f)); AssertTermEquals("fox", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(3.5f)); AssertTermEquals("jumped", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(0.5f)); AssertTermEquals("over", filter, termAtt, payAtt, null); AssertTermEquals("the", filter, termAtt, payAtt, null); AssertTermEquals("lazy", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(5.0f)); AssertTermEquals("brown", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(99.3f)); AssertTermEquals("dogs", filter, termAtt, payAtt, PayloadHelper.EncodeFloat(83.7f)); assertFalse(filter.IncrementToken()); filter.End(); filter.Dispose(); }