.... using Xapian; .... // , // string xapianBase="H:\\XapianDB\\xap.db"; .... // // private void IndexFolder(string path) { try { if (Directory.Exists(path)) { string[] files=Directory.GetFiles(tbIndexFolder.Text); using (WritableDatabase database=new WritableDatabase(xapianBase, Xapian.Xapian.DB_CREATE_OR_OPEN)) { using (TermGenerator indexer=new TermGenerator()) { using (Stem stemmer=new Xapian.Stem("russian")) { indexer.SetStemmer(stemmer); foreach (string file in files) { using (Document doc=new Document()) { // , doc.SetData(file); indexer.SetDocument(doc); // indexer.IndexText(File.ReadAllText(file, Encoding.GetEncoding(1251))); // database.AddDocument(doc); } } } } } } } catch (Exception ex) { Write("Exception: "+ex.ToString()); } } private void Search(string searchText) { try { // using (Database database=new Database(xapianBase)) { using (Enquire enquire=new Enquire(database)) { using (QueryParser qp=new QueryParser()) { using (Stem stemmer=new Stem("russian")) { Write(stemmer.GetDescription()); qp.SetStemmer(stemmer); qp.SetDatabase(database); qp.SetStemmingStrategy(QueryParser.stem_strategy.STEM_SOME); using (Query query=qp.ParseQuery(searchText)) { Write("Parsed query is: "+query.GetDescription()); enquire.SetQuery(query); // // 100 MSet matches=enquire.GetMSet(0, 100); Write(String.Format("{0} results found.", matches.GetMatchesEstimated())); Write(String.Format("Matches 1-{0}:", matches.Size())); // MSetIterator m=matches.Begin(); // while (m!=matches.End()) { Write(String.Format("{0}: {1}% docid={2} [{3}]\n", m.GetRank()+1, m.GetPercent(), m.GetDocId(), m.GetDocument().GetData())); ++m; } } } } } } } catch (Exception ex) { Write("Exception: "+ex.ToString()); } }
Number of words | Search | Time |
one | one | 1883 ms |
one | 2 | 28 ms |
one | 3 | 31 ms |
2 | one | 175 ms |
2 | 2 | 36 ms |
2 | 3 | 41 ms |
3 | one | 1074 ms |
3 | 2 | 35 ms |
3 | 3 | 37 ms |
Source: https://habr.com/ru/post/113381/
All Articles