void SearchDatabase() { ReadOnlyTransaction t = db.StartReadWriteTransaction(); // Find all patients with age > 50 which are diagnosed flu in last September foreach (Item patient in t.Find(Predicate.Value("age") > 50 & Predicate.Value("diagnosis").In(Predicate.Value("date").Between("2010-09-01", "2010-09-30") & Predicate.Value("disease").In(Predicate.Value("name") == "flu")))) { Console.WriteLine("Patient " + patient.GetString("name") + ", age " + patient.GetNumber("age")); } // Print list of diseases with high temperature symptom ordered by name foreach (Item disease in t.Find(Predicate.Value("class") == "disease" & Predicate.Value("symptoms") == "high temperature", new OrderBy("name"))) { Console.WriteLine("Diseas " + disease.GetString("name")); Object symptoms = disease.GetAttribute("symptoms"); if (symptoms is String) { Console.WriteLine("Symptom: " + symptoms); } else if (symptoms is String[]) { Console.WriteLine("Symptoms: "); String[] ss = (String[])symptoms; for (int i = 0; i < ss.Length; i++) { Console.WriteLine("{0}: {1}", i, ss[i]); } } } t.Commit(); }
void SearchDatabase() { ReadOnlyTransaction t = db.StartReadWriteTransaction(); DateTime start = DateTime.Now; int nBooks = nAuthors * nBooksPerAutor / nCoauthors; for (int i = 0, j = 0; i < nBooks; i++) { // find authors of the book Item[] authors = Enumerable.ToArray(t.Find(Predicate.Value("-author").In(Predicate.Value("title") == GenerateTitle(i)))); Debug.Assert(authors.Length == nCoauthors); for (int k = 0; k < nCoauthors; k++) { Debug.Assert(authors[k].GetString("name") == GenerateName(j++ % nAuthors)); } } for (int i = 0; i < nAuthors; i++) { // find book written by this author Item[] books = Enumerable.ToArray(t.Find(Predicate.Value("author").In(Predicate.Value("name") == GenerateName(i)))); Debug.Assert(books.Length == nBooksPerAutor); } Console.WriteLine("Elapsed time for searching database " + (DateTime.Now - start)); start = DateTime.Now; for (int i = 0, mask = 0; i < nBooks; i++, mask = ~mask) { // find book using full text search part of book title and ISDN FullTextSearchResult result = t.FullTextSearch(GenerateWord(i ^ mask) + " " + GenerateISBN(i), MAX_FULL_TEXT_SEARCH_RESULTS, MAX_FULL_TEXT_SEARCH_TIME); Debug.Assert(result.Hits.Length == 1); } for (int i = 0, mask = 0; i < nAuthors; i++, mask = ~mask) { // find authors using full text search of author's name FullTextSearchResult result = t.FullTextSearch(GenerateName(i ^ mask), MAX_FULL_TEXT_SEARCH_RESULTS, MAX_FULL_TEXT_SEARCH_TIME); Debug.Assert(result.Hits.Length == 1); } Console.WriteLine("Elapsed time for full text search " + (DateTime.Now - start)); t.Commit(); }