示例#1
0
        public void String8_Basics()
        {
            byte[] b1 = null, b2 = null, b3 = null;

            String8 one  = String8.Copy("one", ref b1);
            String8 two  = String8.Copy("two", ref b2);
            String8 one2 = String8.Copy("one", ref b3);

            Assert.IsFalse(one.Equals(two));
            Assert.AreNotEqual(one.GetHashCode(), two.GetHashCode());

            Assert.IsTrue(one.Equals(one2));
            Assert.AreEqual(one.GetHashCode(), one2.GetHashCode());

            Assert.IsTrue(one.CompareTo(two) < 0);
            Assert.IsTrue(two.CompareTo(one) > 0);
            Assert.AreEqual(0, one.CompareTo(one2));
            Assert.AreEqual(0, one.CompareTo(one));
        }
示例#2
0
        private static void SearchAll(string bionRootPath)
        {
            List <BionSearcher> searchers = new List <BionSearcher>();

            try
            {
                using (new ConsoleWatch($"Loading Indices under {bionRootPath}...",
                                        () => $"Done; {searchers.Count:n0} loaded"))
                {
                    foreach (string bionFilePath in Directory.GetFiles(bionRootPath, "*.bion", SearchOption.AllDirectories))
                    {
                        BionSearcher searcher = new BionSearcher(bionFilePath, 4);

                        lock (searchers)
                        {
                            searchers.Add(searcher);
                        }
                    }
                }

                int    searchCount = 0;
                int    resultLimit = 100;
                string outputRoot  = "SearchOut";
                byte[] buffer      = null;

                string outputPath = null;
                int    matchCount = 0;

                Directory.CreateDirectory(outputRoot);

                while (true)
                {
                    System.Console.Write("> ");
                    string query = System.Console.ReadLine().Trim();
                    if (String.IsNullOrEmpty(query))
                    {
                        break;
                    }

                    String8 term = String8.Copy(query, ref buffer);

                    matchCount = 0;
                    searchCount++;
                    outputPath = Path.Combine(outputRoot, $"Results.{searchCount}.json");

                    using (new ConsoleWatch("", () => $"Done. {matchCount:n0} matches to {outputPath}"))
                    {
                        using (JsonTextWriter writer = new JsonTextWriter(new StreamWriter(outputPath)))
                        {
                            writer.Formatting = Formatting.Indented;
                            writer.WriteStartArray();

                            for (int i = 0; i < searchers.Count; ++i)
                            {
                                ISearchResult result = searchers[i].Find(term);
                                matchCount += searchers[i].Write(writer, result, 0, resultLimit - matchCount);

                                if (matchCount >= resultLimit)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                foreach (BionSearcher searcher in searchers)
                {
                    searcher.Dispose();
                }
            }
        }
示例#3
0
 private static void Search(string filePath, string term)
 {
     byte[] term8 = null;
     Search(filePath, String8.Copy(term, ref term8));
 }