Пример #1
0
        public 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 WhitespaceTokenizer(new StringReader(test)), '|', new FloatEncoder());
            ITermAttribute    termAtt          = filter.GetAttribute <ITermAttribute>();
            IPayloadAttribute payAtt           = filter.GetAttribute <IPayloadAttribute>();

            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));
            Assert.False(filter.IncrementToken());
        }
 /// <summary>
 /// Stores a 32 bit float in the payload, or set it to null if 1f;
 /// </summary>
 /// <param name="token"></param>
 /// <param name="weight"></param>
 public override void SetWeight(Token token, float weight)
 {
     token.Payload = weight == 1f ? null : new Payload(PayloadHelper.EncodeFloat(weight));
 }