Using Redis queues to loop through the search index

Source: Internet
Author: User

1    Public Static voidgetnewslist ()2         {3 4              while(true)5             {6                 using(varClient =RedisManager.ClientManager.GetClient ())7                 {8 gowrite (client);9                 }TenThread.Sleep (60000); One             } A}
Loop Call Write
1     /// <summary>2         ///Start Writing3         /// </summary>4         /// <param name= "writer" ></param>5         /// <param name= "Client" ></param>6         Private Static voidGowrite (ServiceStack.Redis.IRedisClient client)7         {8Fsdirectory directory =NULL;9IndexWriter writer =NULL;Ten  One             Try A             { -                 stringIndexpath ="D:/index";//Note that the case is consistent with the folder on the disk, or it will be error -  theDirectory = Fsdirectory.open (NewDirectoryInfo (Indexpath),Newnativefslockfactory ()); -  -                 //determine if a folder exists -                 BOOLIsexis =indexreader.indexexists (directory); +  -                 if(Isexis) +                 { A                     //if the index directory is locked (for example, the program exits unexpectedly during indexing), the first unlock at                     if(indexwriter.islocked (directory)) -                     { - indexwriter.unlock (directory); -                     } -                 } -  inwriter =NewIndexWriter (Directory,NewPanguanalyzer (),!Isexis, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); -  to                  while(true) +                 { -                     //NID, Ntitle, Ntxt, Ntime, Ntid the                     stringJSON = client. Dequeueitemfromlist ("Newsindex"); *  $                     //Determine if NULLPanax Notoginseng                     if(JSON = =NULL) -                     { the                         //Rest 1 seconds to exit +Thread.Sleep ( +); A                         return; the                     } +                     Else -                     { $JavaScriptSerializer JSS =NewJavaScriptSerializer (); $dictionary<string,Object> dict = (dictionary<string,Object>) JSS. Deserializeobject (JSON); -  -                         //Instantiate News theNews news =NewNews (); -News. Ntitle = dict["Ntitle"]. ToString ();WuyiNews. Ntxt = dict["Ntxt"]. ToString (); theNews. Ntime = dict["Ntime"]. ToString (); -News. NID = Convert.toint64 (dict["NID"]); WuNews. Ntid = Convert.ToInt32 (dict["Ntid"]); -  About                         //writing to the index library $ Writeindex (news, writer); -                     } -                 } -             } A             finally +             { the                 //Close IndexWriter -                 if(Writer! =NULL) $                 { the writer. Close (); the                 } the  the                 //Close Fsdirectory -                 if(Directory! =NULL) in                 { the directory. Close (); the                 } About             } the}
Write
1    /// <summary>2         ///writing to the index library3         /// </summary>4         /// <param name= "News" ></param>5         Private Static voidWriteindex (news, indexwriter writer)6         {7 8             //Write Data9Document document =NewDocument ();Ten  One             //Delete the same data AWriter. Deletedocuments (NewTerm ("NID", News. NID. ToString ())); -             //To delete obsolete files, you need to set the judged field to Field.Index.ANALYZED - writer. Optimize (); the  -Document. ADD (NewField ("Ntitle", News. Ntitle, Field.Store.YES, Field.Index.NOT_ANALYZED)); -Document. ADD (NewField ("Ntxt", News. Ntxt, Field.Store.YES, Field.Index.NOT_ANALYZED)); -Document. ADD (NewField ("NID", News. NID. ToString (), Field.Store.YES, Field.Index.ANALYZED)); +Document. ADD (NewField ("Ntid", News. Ntid. ToString (), Field.Store.YES, Field.Index.NOT_ANALYZED)); -Document. ADD (NewField ("Ntime", News. Ntime.tostring (), Field.Store.YES, Field.Index.NOT_ANALYZED)); +Document. ADD (NewField (" All", News. Ntitle + news. Ntime +News. Ntxt, Field.Store.YES, Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.WITH_POSITIONS_OFFSETS)); A  at  -             //Perform write - writer. Adddocument (document); -Console.WriteLine ("Index Complete"); -}
writing to the index library

Using Redis queues to loop through the search index

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.