"Fossies" - the Fresh Open Source Software Archive

Member "xapian-bindings-1.4.14/csharp/docs/examples/SimpleIndex.cs" (23 Nov 2019, 2135 Bytes) of package /linux/www/xapian-bindings-1.4.14.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Index each paragraph of a text file as a Xapian document.
    2 //
    3 // Copyright (c) 2003 James Aylett
    4 // Copyright (c) 2004,2006,2007 Olly Betts
    5 //
    6 // This program is free software; you can redistribute it and/or
    7 // modify it under the terms of the GNU General Public License as
    8 // published by the Free Software Foundation; either version 2 of the
    9 // License, or (at your option) any later version.
   10 //
   11 // This program is distributed in the hope that it will be useful,
   12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 // GNU General Public License for more details.
   15 //
   16 // You should have received a copy of the GNU General Public License
   17 // along with this program; if not, write to the Free Software
   18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
   19 // USA
   20 
   21 using System;
   22 
   23 class SimpleIndex {
   24     public static void Main(string[] argv) {
   25     if (argv.Length != 1) {
   26         Console.Error.WriteLine("Usage: SimpleIndex PATH_TO_DATABASE");
   27         Environment.Exit(1);
   28     }
   29 
   30     try {
   31         // Open the database for update, creating a new database if
   32         // necessary.
   33         Xapian.WritableDatabase database;
   34         database = new Xapian.WritableDatabase(argv[0], Xapian.Xapian.DB_CREATE_OR_OPEN);
   35 
   36         Xapian.TermGenerator indexer = new Xapian.TermGenerator();
   37         Xapian.Stem stemmer = new Xapian.Stem("english");
   38         indexer.SetStemmer(stemmer);
   39 
   40         string para = "";
   41         while (true) {
   42         string line = Console.In.ReadLine();
   43         if (line == null) {
   44             if (para == "") break;
   45             line = "";
   46         }
   47         line = line.Trim();
   48         if (line == "") {
   49             if (para != "") {
   50             // We've reached the end of a paragraph, so index it.
   51             Xapian.Document doc = new Xapian.Document();
   52             doc.SetData(para);
   53 
   54             indexer.SetDocument(doc);
   55             indexer.IndexText(para);
   56 
   57             // Add the document to the database.
   58             database.AddDocument(doc);
   59             para = "";
   60             }
   61         } else {
   62             if (para != "") para += " ";
   63             para += line;
   64         }
   65         }
   66     } catch (Exception e) {
   67         Console.Error.WriteLine("Exception: " + e.ToString());
   68         Environment.Exit(1);
   69     }
   70     }
   71 }