public void TestingTierIndex() { //Path to where all the bin file will be write to string pathToIndex = Path.Join(corpusDir, "/index/"); //Let Indexer know where should it writes all bin files Indexer.path = pathToIndex; //Read corpus IDocumentCorpus corpus = DirectoryCorpus.LoadTextDirectory(corpusDir); //Load Corpus to Index IIndex index = Indexer.IndexCorpus(corpus); //Create new DiskPositional Index from on disk files index = new DiskPositionalIndex(pathToIndex); //Check Info Of Postings Collected from Tier 1 IList<String> results = new List<string>(); //The rest of your code... List<string> terms = new List<string>(); terms.Add("hello"); terms.Add("world"); //get the postings IList<Posting> postings = new List<Posting>(); postings = index.GetPositionalPostings(terms); //add the count of the postings to the list of strings to be returned results.Add(postings.Count.ToString()); foreach (Posting p in postings) { if (results.Count < 20) { //use the document id to access the document IDocument doc = corpus.GetDocument(p.DocumentId); results.Add(doc.Title); results.Add(doc.DocumentId.ToString()); } } foreach (string s in results) { Console.WriteLine(s); } } //end TestingTierIndexer()
/// <summary> /// Returns postings for soundex query /// </summary> /// <param name="name">the author name being queried</param> public List <string> SearchSoundexQuery(string name) { //list of strings to return List <String> results = new List <string>(); try { //get a list of postings given the name IList <Posting> postings = new DiskSoundEx(Indexer.path).GetPostings(name); //if the query returns any results if (postings.Count > 0) { //add the number of postings to the list of strings to return results.Add(postings.Count.ToString()); //for each posting foreach (Posting p in postings) { //use the posting's id to access the document IDocument doc = corpus.GetDocument(p.DocumentId); //add the title and name of the author to the list of strings to be returned results.Add(doc.Title + " (Author: " + doc.Author + ")"); //also add the document id to the list of strings to be returned results.Add(doc.DocumentId.ToString()); } } else { //if there are no postings just return a list with a zero in it results.Add("0"); } //return the final list of strings } catch (Exception e) { Console.WriteLine(e); } return(results); }