コード例 #1
0
ファイル: FloatEncoder.cs プロジェクト: zalintyre/lucenenet
        public override BytesRef Encode(char[] buffer, int offset, int length)
        {
            float payload = float.Parse(new string(buffer, offset, length), CultureInfo.InvariantCulture); //TODO: improve this so that we don't have to new Strings

            byte[]   bytes  = PayloadHelper.EncodeSingle(payload);
            BytesRef result = new BytesRef(bytes);

            return(result);
        }
コード例 #2
0
 public NumericPayloadTokenFilter(TokenStream input, float payload, string typeMatch)
     : base(input)
 {
     if (typeMatch is null)
     {
         throw new ArgumentNullException(nameof(typeMatch), "typeMatch cannot be null"); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention)
     }
     //Need to encode the payload
     thePayload      = new BytesRef(PayloadHelper.EncodeSingle(payload));
     this.typeMatch  = typeMatch;
     this.payloadAtt = AddAttribute <IPayloadAttribute>();
     this.typeAtt    = AddAttribute <ITypeAttribute>();
 }
コード例 #3
0
 public NumericPayloadTokenFilter(TokenStream input, float payload, string typeMatch)
     : base(input)
 {
     if (typeMatch == null)
     {
         throw new ArgumentException("typeMatch cannot be null");
     }
     //Need to encode the payload
     thePayload      = new BytesRef(PayloadHelper.EncodeSingle(payload));
     this.typeMatch  = typeMatch;
     this.payloadAtt = AddAttribute <IPayloadAttribute>();
     this.typeAtt    = AddAttribute <ITypeAttribute>();
 }
コード例 #4
0
        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 SingleEncoder());
            ICharTermAttribute          termAtt = filter.GetAttribute <ICharTermAttribute>();
            IPayloadAttribute           payAtt  = filter.GetAttribute <IPayloadAttribute>();

            filter.Reset();
            AssertTermEquals("The", filter, termAtt, payAtt, null);
            AssertTermEquals("quick", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(1.0f));
            AssertTermEquals("red", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(2.0f));
            AssertTermEquals("fox", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(3.5f));
            AssertTermEquals("jumped", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(0.5f));
            AssertTermEquals("over", filter, termAtt, payAtt, null);
            AssertTermEquals("the", filter, termAtt, payAtt, null);
            AssertTermEquals("lazy", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(5.0f));
            AssertTermEquals("brown", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(99.3f));
            AssertTermEquals("dogs", filter, termAtt, payAtt, PayloadHelper.EncodeSingle(83.7f));
            assertFalse(filter.IncrementToken());
            filter.End();
            filter.Dispose();
        }