Example #1
0
        private static void ApplyOn(string databaseName, ICollection queue, bool optimize)
        {
            try {
                log.InfoFormat("Applying updates to {0}", databaseName);

                SearchReader reader = new SearchReader(databaseName, SearchReader.CreateIfNew);
                foreach (UpdateRecord record in queue)
                {
                    log.InfoFormat("Applying read pass: {0}", record);
                    record.ApplyReads(reader);
                }
                reader.Close();

                SearchWriter writer = new SearchWriter(databaseName);
                foreach (UpdateRecord record in queue)
                {
                    log.InfoFormat("Applying write pass: {0}", record);
                    record.ApplyWrites(writer);
                }
                if (optimize)
                {
                    writer.Optimize();
                }
                writer.Close();

                log.InfoFormat("Closed updates on {0}", databaseName);
            } catch (Exception e) {
                log.ErrorFormat("Unexpected error in update for {0}: {1}", databaseName, e);
                return;
            }
        }
Example #2
0
        static void ImportDump(string dumpfile, string database)
        {
            InputStream input = Tools.openInputFile(dumpfile);

            SearchWriter state = new SearchWriter(database);

            state.InitializeIndex();

            XmlDumpReader reader = new XmlDumpReader(input,
                                                     new ProgressFilter(new SearchImporter(state), 100));

            reader.readDump();

            state.Close();
            Console.WriteLine("Optimizing...");
            state.Optimize();
        }
Example #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("MediaWiki Lucene search indexer - index manipulation tool.\n");

            string    configSection = "Updater";
            ArrayList databases     = new ArrayList();
            string    action        = null;
            string    source        = null;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "--daemon")
                {
                    configSection = "Daemon";
                }
                else if (args[i] == "--optimize")
                {
                    action = "optimize";
                }
                else if (args[i].StartsWith("--import"))
                {
                    string[] bits = args[i].Split(new char[] { '=' }, 2);
                    action = "import";
                    source = bits[1];
                }
                else if (!args[i].StartsWith("--"))
                {
                    databases.Add(args[i]);
                }
            }

            if (action == null)
            {
                Console.WriteLine("No action specified; try --optimize.");
                System.Environment.Exit(-1);
            }

            if (databases.Count == 0)
            {
                Console.WriteLine("Cowardly refusing to operate with no databases given.");
                System.Environment.Exit(-1);
            }

            Configuration.SetIndexSection(configSection);
            config = Configuration.Open();

            if (action == "optimize")
            {
                foreach (string dbname in databases)
                {
                    try {
                        SearchWriter state = new SearchWriter(dbname);
                        Console.WriteLine("Optimizing " + dbname);
                        state.Optimize();
                    } catch (Exception e) {
                        Console.WriteLine(e);
                    }
                }
            }
            else if (action == "import")
            {
                if (databases.Count > 1)
                {
                    Console.WriteLine("Warning! Only the first database given will be imported (" + databases[0] + ")");
                }
                ImportDump(source, (string)databases[0]);
            }

            Console.WriteLine("Done!");
        }
Example #4
0
 public override void ApplyWrites(SearchWriter state)
 {
     state.AddArticle(_article, _metadata);
 }
Example #5
0
 /**
  * Updates to run on a lucene IndexWriter.
  * These are run in a second pass after the reads.
  */
 public abstract void ApplyWrites(SearchWriter state);
Example #6
0
 public override void ApplyWrites(SearchWriter state)
 {
     // do nothing
 }
 public SearchImporter(SearchWriter writer)
 {
     _writer = writer;
 }