• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# BytesRef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中BytesRef的典型用法代码示例。如果您正苦于以下问题:C# BytesRef类的具体用法?C# BytesRef怎么用?C# BytesRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BytesRef类属于命名空间,在下文中一共展示了BytesRef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Encode

 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;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:FloatEncoder.cs


示例2: Encode

 public override BytesRef Encode(char[] buffer, int offset, int length)
 {
     int payload = ArrayUtil.ParseInt(buffer, offset, length); //TODO: improve this so that we don't have to new Strings
     byte[] bytes = PayloadHelper.EncodeInt(payload);
     BytesRef result = new BytesRef(bytes);
     return result;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:IntegerEncoder.cs


示例3: Decompress

 internal virtual byte[] Decompress(byte[] compressed, int originalLength, int offset, int length)
 {
     Decompressor decompressor = Mode.NewDecompressor();
     BytesRef bytes = new BytesRef();
     decompressor.Decompress(new ByteArrayDataInput(compressed), originalLength, offset, length, bytes);
     return Arrays.CopyOfRange(bytes.Bytes, bytes.Offset, bytes.Offset + bytes.Length);
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:AbstractTestCompressionMode.cs


示例4: TestBlendingType

        public void TestBlendingType()
        {

            BytesRef pl = new BytesRef("lake");
            long w = 20;

            Input[] keys = new Input[]{
                new Input("top of the lake", w, pl)
            };

            DirectoryInfo tempDir = CreateTempDir("BlendedInfixSuggesterTest");
            Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET);

            // BlenderType.LINEAR is used by default (remove position*10%)
            BlendedInfixSuggester suggester = new BlendedInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a);
            suggester.Build(new InputArrayIterator(keys));

            assertEquals(w, GetInResults(suggester, "top", pl, 1));
            assertEquals((int)(w * (1 - 0.10 * 2)), GetInResults(suggester, "the", pl, 1));
            assertEquals((int)(w * (1 - 0.10 * 3)), GetInResults(suggester, "lake", pl, 1));

            suggester.Dispose();

            // BlenderType.RECIPROCAL is using 1/(1+p) * w where w is weight and p the position of the word
            suggester = new BlendedInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a,
                                                  AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS, BlendedInfixSuggester.BlenderType.POSITION_RECIPROCAL, 1);
            suggester.Build(new InputArrayIterator(keys));

            assertEquals(w, GetInResults(suggester, "top", pl, 1));
            assertEquals((int)(w * 1 / (1 + 2)), GetInResults(suggester, "the", pl, 1));
            assertEquals((int)(w * 1 / (1 + 3)), GetInResults(suggester, "lake", pl, 1));

            suggester.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:34,代码来源:BlendedInfixSuggesterTest.cs


示例5: MockVariableLengthPayloadFilter

 public MockVariableLengthPayloadFilter(Random random, TokenStream @in)
     : base(@in)
 {
     this.Random = random;
     this.Payload = new BytesRef(Bytes);
     this.PayloadAtt = AddAttribute<IPayloadAttribute>();
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:7,代码来源:MockVariableLengthPayloadFilter.cs


示例6: DocFreqValueSource

 public DocFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
 {
     this.field = field;
     this.val = val;
     this.indexedField = indexedField;
     this.indexedBytes = indexedBytes;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:7,代码来源:DocFreqValueSource.cs


示例7: TermStats

 internal TermStats(string field, BytesRef termtext, int df, long tf)
 {
     this.termtext = BytesRef.DeepCopyOf(termtext);
     this.Field = field;
     this.DocFreq = df;
     this.TotalTermFreq = tf;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:TermStats.cs


示例8: TestFarsiRangeFilterCollating

        public virtual void TestFarsiRangeFilterCollating(Analyzer analyzer, BytesRef firstBeg, BytesRef firstEnd, BytesRef secondBeg, BytesRef secondEnd)
        {
            Directory dir = NewDirectory();
            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
            Document doc = new Document();
            doc.Add(new TextField("content", "\u0633\u0627\u0628", Field.Store.YES));
            doc.Add(new StringField("body", "body", Field.Store.YES));
            writer.AddDocument(doc);
            writer.Dispose();
            IndexReader reader = DirectoryReader.Open(dir);
            IndexSearcher searcher = new IndexSearcher(reader);
            Query query = new TermQuery(new Term("body", "body"));

            // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
            // orders the U+0698 character before the U+0633 character, so the single
            // index Term below should NOT be returned by a TermRangeFilter with a Farsi
            // Collator (or an Arabic one for the case when Farsi searcher not
            // supported).
            ScoreDoc[] result = searcher.Search(query, new TermRangeFilter("content", firstBeg, firstEnd, true, true), 1).ScoreDocs;
            Assert.AreEqual(0, result.Length, "The index Term should not be included.");

            result = searcher.Search(query, new TermRangeFilter("content", secondBeg, secondEnd, true, true), 1).ScoreDocs;
            Assert.AreEqual(1, result.Length, "The index Term should be included.");

            reader.Dispose();
            dir.Dispose();
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:27,代码来源:CollationTestBase.cs


示例9: AddValue

        public virtual void AddValue(int docID, BytesRef value)
        {
            if (value == null)
            {
                throw new System.ArgumentException("field \"" + FieldInfo.Name + "\": null value not allowed");
            }
            if (value.Length > (ByteBlockPool.BYTE_BLOCK_SIZE - 2))
            {
                throw new System.ArgumentException("DocValuesField \"" + FieldInfo.Name + "\" is too large, must be <= " + (ByteBlockPool.BYTE_BLOCK_SIZE - 2));
            }

            if (docID != CurrentDoc)
            {
                FinishCurrentDoc();
            }

            // Fill in any holes:
            while (CurrentDoc < docID)
            {
                PendingCounts.Add(0); // no values
                CurrentDoc++;
            }

            AddOneValue(value);
            UpdateBytesUsed();
        }
开发者ID:paulirwin,项目名称:lucene.net,代码行数:26,代码来源:SortedSetDocValuesWriter.cs


示例10: TestSize

 public virtual void TestSize()
 {
     BytesRef @ref = new BytesRef();
     int num = AtLeast(2);
     for (int j = 0; j < num; j++)
     {
         int mod = 1 + Random().Next(39);
         for (int i = 0; i < 797; i++)
         {
             string str;
             do
             {
                 str = TestUtil.RandomRealisticUnicodeString(Random(), 1000);
             } while (str.Length == 0);
             @ref.CopyChars(str);
             int count = Hash.Size();
             int key = Hash.Add(@ref);
             if (key < 0)
             {
                 Assert.AreEqual(Hash.Size(), count);
             }
             else
             {
                 Assert.AreEqual(Hash.Size(), count + 1);
             }
             if (i % mod == 0)
             {
                 Hash.Clear();
                 Assert.AreEqual(0, Hash.Size());
                 Hash.Reinit();
             }
         }
     }
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:34,代码来源:TestBytesRefHash.cs


示例11: Main

        public static void Main(string[] args)
        {
            FileInfo input = new FileInfo("/home/dweiss/tmp/shuffled.dict");

            int buckets = 20;
            int shareMaxTail = 10;

            ExternalRefSorter sorter = new ExternalRefSorter(new OfflineSorter());
            FSTCompletionBuilder builder = new FSTCompletionBuilder(buckets, sorter, shareMaxTail);

            TextReader reader =
                new StreamReader(
                    new FileStream(input.FullName, FileMode.Open), Encoding.UTF8);

            BytesRef scratch = new BytesRef();
            string line;
            int count = 0;
            while ((line = reader.ReadLine()) != null)
            {
                scratch.CopyChars(line);
                builder.Add(scratch, count % buckets);
                if ((count++ % 100000) == 0)
                {
                    Console.WriteLine("Line: " + count);
                }
            }

            Console.WriteLine("Building FSTCompletion.");
            FSTCompletion completion = builder.Build();

            FileInfo fstFile = new FileInfo("completion.fst");
            Console.WriteLine("Done. Writing automaton: " + fstFile.FullName);
            completion.FST.Save(fstFile);
            sorter.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:35,代码来源:LargeInputFST.cs


示例12: TruncatedToPrefixAndPattern

        protected virtual void TruncatedToPrefixAndPattern()
        {
            int i = 0;
            while ((i < truncated.Length) && MatchingChar(truncated[i]))
            {
                i++;
            }
            prefix = truncated.Substring(0, i);
            prefixRef = new BytesRef(prefix);

            StringBuilder re = new StringBuilder();
            // LUCENENET NOTE: To mimic Java's matches() method, we alter
            // the Regex to match the entire string. This makes the Regex
            // fail fast when not at the beginning of the string, which is
            // more efficient than testing the length after a successful match.
            // http://stackoverflow.com/a/12547528/181087
            re.Append(@"\A(?:");
            while (i < truncated.Length)
            {
                AppendRegExpForChar(truncated[i], re);
                i++;
            }
            re.Append(@")\z");
            pattern = new Regex(re.ToString(), RegexOptions.Compiled);
        }
开发者ID:apache,项目名称:lucenenet,代码行数:25,代码来源:SrndTruncQuery.cs


示例13: SumValues

        private void SumValues(IList<FacetsCollector.MatchingDocs> matchingDocs)
        {
            //System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName);
            foreach (FacetsCollector.MatchingDocs hits in matchingDocs)
            {
                BinaryDocValues dv = hits.context.AtomicReader.GetBinaryDocValues(IndexFieldName);
                if (dv == null) // this reader does not have DocValues for the requested category list
                {
                    continue;
                }

                DocIdSetIterator docs = hits.bits.GetIterator();

                int doc;
                while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    //System.out.println("  doc=" + doc);
                    // TODO: use OrdinalsReader?  we'd need to add a
                    // BytesRef getAssociation()?
                    BytesRef bytesRef = new BytesRef();
                    dv.Get(doc, bytesRef);
                    byte[] bytes = bytesRef.Bytes;
                    int end = bytesRef.Offset + bytesRef.Length;
                    int offset = bytesRef.Offset;
                    while (offset < end)
                    {
                        int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                        offset += 4;
                        int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                        offset += 4;
                        values[ord] += value;
                    }
                }
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:35,代码来源:TaxonomyFacetSumIntAssociations.cs


示例14: TestBlendedSort

        public void TestBlendedSort()
        {

            BytesRef payload = new BytesRef("star");

            Input[] keys = new Input[]{
                new Input("star wars: episode v - the empire strikes back", 8, payload)
            };

            DirectoryInfo tempDir = CreateTempDir("BlendedInfixSuggesterTest");

            Analyzer a = new StandardAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET);
            BlendedInfixSuggester suggester = new BlendedInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a,
                                                                        AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS,
                                                                        BlendedInfixSuggester.BlenderType.POSITION_LINEAR,
                                                                        BlendedInfixSuggester.DEFAULT_NUM_FACTOR);
            suggester.Build(new InputArrayIterator(keys));

            // we query for star wars and check that the weight
            // is smaller when we search for tokens that are far from the beginning

            long w0 = GetInResults(suggester, "star ", payload, 1);
            long w1 = GetInResults(suggester, "war", payload, 1);
            long w2 = GetInResults(suggester, "empire ba", payload, 1);
            long w3 = GetInResults(suggester, "back", payload, 1);
            long w4 = GetInResults(suggester, "bacc", payload, 1);

            assertTrue(w0 > w1);
            assertTrue(w1 > w2);
            assertTrue(w2 > w3);

            assertTrue(w4 < 0);

            suggester.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:35,代码来源:BlendedInfixSuggesterTest.cs


示例15: BufferedInputIterator

 /// <summary>
 /// Creates a new iterator, buffering entries from the specified iterator </summary>
 public BufferedInputIterator(InputIterator source)
 {
     BytesRef spare;
     int freqIndex = 0;
     hasPayloads = source.HasPayloads;
     hasContexts_Renamed = source.HasContexts;
     while ((spare = source.Next()) != null)
     {
         entries.Append(spare);
         if (hasPayloads)
         {
             payloads.Append(source.Payload);
         }
         if (hasContexts_Renamed)
         {
             contextSets.Add(source.Contexts);
         }
         if (freqIndex >= freqs.Length)
         {
             freqs = ArrayUtil.Grow(freqs, freqs.Length + 1);
         }
         freqs[freqIndex++] = source.Weight;
     }
     comp = source.Comparator;
 }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:27,代码来源:BufferedInputIterator.cs


示例16: TestEmpty

 public virtual void TestEmpty()
 {
     BytesRef b = new BytesRef();
     Assert.AreEqual(BytesRef.EMPTY_BYTES, b.Bytes);
     Assert.AreEqual(0, b.Offset);
     Assert.AreEqual(0, b.Length);
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:7,代码来源:TestBytesRef.cs


示例17: TestSimpleDictionary

        public virtual void TestSimpleDictionary()
        {
            using (System.IO.Stream affixStream = this.GetType().getResourceAsStream("simple.aff"))
            {
                using (System.IO.Stream dictStream = this.GetType().getResourceAsStream("simple.dic"))
                {

                    Dictionary dictionary = new Dictionary(affixStream, dictStream);
                    assertEquals(3, dictionary.LookupSuffix(new char[] { 'e' }, 0, 1).Length);
                    assertEquals(1, dictionary.LookupPrefix(new char[] { 's' }, 0, 1).Length);
                    IntsRef ordList = dictionary.LookupWord(new char[] { 'o', 'l', 'r' }, 0, 3);
                    assertNotNull(ordList);
                    assertEquals(1, ordList.Length);

                    BytesRef @ref = new BytesRef();
                    dictionary.flagLookup.Get(ordList.Ints[0], @ref);
                    char[] flags = Dictionary.DecodeFlags(@ref);
                    assertEquals(1, flags.Length);

                    ordList = dictionary.LookupWord(new char[] { 'l', 'u', 'c', 'e', 'n' }, 0, 5);
                    assertNotNull(ordList);
                    assertEquals(1, ordList.Length);
                    dictionary.flagLookup.Get(ordList.Ints[0], @ref);
                    flags = Dictionary.DecodeFlags(@ref);
                    assertEquals(1, flags.Length);
                }
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:28,代码来源:TestDictionary.cs


示例18: TestCopyBytes

 public virtual void TestCopyBytes()
 {
     sbyte[] bytes = new sbyte[] { (sbyte)'a', (sbyte)'b', (sbyte)'c', (sbyte)'d' };
     BytesRef b = new BytesRef(bytes, 1, 3); // bcd
     b.CopyBytes(new BytesRef("bcde"));
     Assert.AreEqual("bcde", b.Utf8ToString());
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:7,代码来源:TestBytesRef.cs


示例19: SrndPrefixQuery

 public SrndPrefixQuery(string prefix, bool quoted, char truncator)
     : base(quoted)
 {
     this.prefix = prefix;
     prefixRef = new BytesRef(prefix);
     this.truncator = truncator;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:SrndPrefixQuery.cs


示例20: TestAppend

 public virtual void TestAppend()
 {
     var bytes = new[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d' };
     BytesRef b = new BytesRef(bytes, 1, 3); // bcd
     b.Append(new BytesRef("e"));
     Assert.AreEqual("bcde", b.Utf8ToString());
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:7,代码来源:TestBytesRef.cs



注:本文中的BytesRef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# C1类代码示例发布时间:2022-05-24
下一篇:
C# ByteVector类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap