lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "hu andy" <andyh...@gmail.com>
Subject Re: Consult some information about adding index while searching
Date Fri, 28 Jul 2006 08:28:14 GMT
These codes are written in C#,. There is a C# version of Lucene 1.9, which
can be downloaded from http://www.dotlucene.net
This implements the indexing .
      public void CreateIndex()
        {
            try
            {
                AddDirectory(directory);
                writer.Optimize();
                writer.Close();
                directory.Refresh();
            }
            catch (Exception e)
            {
                fmLog.AddLog(fmLog.LogType.Error, Current.User.ID, e.Message
);
                return;
            }
        }

This is a wrapper of IndexSearcher. At first , I want to use a singleton
IndexSearcher. But then I found the updated document can't be retrieved
immediately. So Every time I instantiate a new IndexSeacher, although it is
inefficient.
    public class SingletonSearcher
    {
        SingletonSearcher searcher
        IndexSearcher indexSearcher = null;
        static Object o = typeof(SingletonSearcher);


        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>

        private SingletonSearcher(String indexPath)
        {
            try
            {
                indexSearcher = new IndexSearcher(indexPath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                searcher = null;
            }
        }
        public static SingletonSearcher GetSearcher()
        {
            //lock (o)
            //{
            //    if (searcher == null)
            //       searcher = new SingletonSearcher(Current.Server.Path);
            //    return searcher;
            //}
            return new SingletonSearcher(Current.Server.Path);
        }

        public static Hits GetHits(Query query)
        {
            if (GetSearcher() == null)
                return null;
            else if (GetSearcher().indexSearcher == null)
                return null;
            return GetSearcher().indexSearcher.Search(query);
        }
}

2006/7/28, Doron Cohen <DORONC@il.ibm.com>:
>
> > Yes, I have closed IndexWriter.  But it doesn't work.
>
> This is strange...
> Can you post a small version of your code that can be executed to show the
> problem?
> - Doron
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message