´«ÖDz¥¿Íjavaѧϰ lucene³õ²½
ÒòΪ¼´½«ÒªÑ§Ï°lucene£¬ËùÒÔÎÒÌáǰԤϰÁËluceneµÄÏà¹Ø֪ʶ£¬
1£¬luceneÊÇÖÚ¶àËÑË÷ÒýÇæÖеÄÒ»¸ö£¬¾ÍÏñ³Ö¾Ã²ã³ýÁËHibernateÍâÒ²ÓкܶàÆäËü¿ò¼Ü
Ò»Ñù¡£LuceneÊÇÒ»¸ö¿ª·¢¹¤¾ß°ü£¬ÎÒÃÇ¿ÉÒÔʹÓÃËûΪӦÓóÌÐòÌí¼ÓÈ«ÎļìË÷µÄ¹¦ÄÜ¡£
2£¬Ä¿Ç°ÒѾÓкܶàÓ¦ÓóÌÐòµÄËÑË÷¹¦ÄÜÊÇ»ùÓÚ Lucene µÄ£¬±ÈÈç Eclipse µÄ°ïÖúϵ
ͳµÄËÑË÷¹¦ÄÜ¡£ »¹ÓÐÆäËûºÜ¶àµÄÍøÕ¾µÄÓ¦ÓóÌÐòʹÓÃÁËLucene¡£
3£¬Lucene Äܹ»ÎªÎı¾ÀàÐ͵ÄÊý¾Ý½¨Á¢Ë÷Òý£¬ËùÒÔÄãÖ»ÒªÄÜ°ÑÄãÒªË÷ÒýµÄÊý¾Ý¸ñʽת
»¯µÄÎı¾µÄ£¬Lucene ¾ÍÄܶÔÄãµÄÎĵµ½øÐÐË÷ÒýºÍËÑË÷¡£
ʹÓò½Ö裺
1£¬×¼±¸»·¾³£ºÌí¼Ójar°ü
lucene-core-2.4.0.jar£¨ºËÐÄ£©£»
lucene-analyzers-2.4.0.jar£¨·Ö´ÊÆ÷£©£»
lucene-highlighter-2.4.0.jar£¨¸ßÁÁÆ÷£©£»
a) ½¨Á¢Ë÷Òý.
b) ½øÐÐËÑË÷.
2£¬¹¹ÔìIndexWriter¡£IndexWriterÊÇLuceneÓÃÀ´´´½¨Ë÷ÒýµÄÒ»¸öºËÐĵÄÀࡣʹÓÃ
¹¹Ôì·½·¨IndexWriter(Directory d, Analyzer a, MaxFieldLength mfl); Èç¹û
Ë÷Òý²»´æÔÚ£¬¾Í»á±»´´½¨¡£
Directory£¬´ú±íÁË Lucene µÄË÷ÒýµÄ´æ´¢µÄλÖá£ÕâÊÇÒ»¸ö³éÏóÀ࣬³£ÓõÄÓÐÁ½
¸öʵÏÖ£¬µÚÒ»¸öÊÇ FSDirectory£¬Ëü±íʾһ¸ö´æ´¢ÔÚÎļþϵͳÖеÄË÷ÒýλÖᣵÚ
¶þ¸öÊÇ RAMDirectory£¬Ëü±íʾһ¸ö´æ´¢ÔÚÄÚ´æµ±ÖеÄË÷ÒýλÖá£
Analyzer£¬ÔÚÒ»¸öÎĵµ±»Ë÷Òý֮ǰ£¬Ê×ÏÈÐèÒª¶ÔÎĵµÄÚÈݽøÐзִʴ¦Àí£¬Õⲿ·Ö
¹¤×÷¾ÍÊÇÓÉ Analyzer À´×öµÄ¡£Analyzer ÀàÊÇÒ»¸ö³éÏóÀ࣬ËüÓжà¸öʵÏÖ¡£Õë¶Ô
²»Í¬µÄÓïÑÔºÍÓ¦ÓÃÐèҪѡÔñÊÊºÏµÄ Analyzer¡£Analyzer °Ñ·Ö´ÊºóµÄÄÚÈݽ»¸ø
IndexWriter À´½¨Á¢Ë÷Òý¡£
MaxFieldLength£¬ÓÃÓÚÏÞÖÆFieldµÄ´óС¡£Õâ¸ö±äÁ¿¿ÉÒÔÈÃÓû§Óмƻ®µØ¶Ô´óÎĵµ
Field½øÐнØÈ¡¡£¼ÙÈçȡֵΪ10000£¬¾ÍÖ»Ë÷Òýÿ¸öFieldµÄÇ°10000¸öTerm£¨¹Ø¼ü
×Ö£©¡£Ò²¾ÍÊÇ˵ÿ¸öFieldÖÐÖ»ÓÐÇ°10000¸öTerm£¨¹Ø¼ü×Ö£©½¨Á¢Ë÷Òý£¬³ý´ËÖ®Íâ
µÄ²¿·Ö¶¼²»»á±»LuceneË÷Òý£¬µ±È»Ò²²»Äܱ»ËÑË÷µ½¡£
3£¬´´½¨Ë÷Òý£¬Ê¹Ó÷½·¨IndexWriter.addDocument(Document doc)¡£
Document£¬ÊÇÓÃÀ´ÃèÊöLuceneÎĵµ½á¹¹µÄ¡£ÈκÎÐèÒª½øÐÐË÷ÒýµÄÊý¾Ý¶¼±ØÐëת»¯
³ÉDocument¶ÔÏó¡£DocumentÊÇË÷ÒýºÍËÑË÷µÄ×î»ù±¾µ¥Ôª£¬ÊÇÒ»×éFieldµÄ¼¯ºÏ¡£
Field£¬×é³ÉDocumentµÄÔªËØ£¬ÓÃÀ´ÃèÊöÒ»¸öÎĵµµÄij¸öÊôÐԵģ¬±ÈÈçÒ»·âµç×ÓÓÊ
¼þµÄ±êÌâºÍÄÚÈÝ¿ÉÒÔÓÃÁ½¸öField¶ÔÏó·Ö±ðÃèÊö¡£FieldÊÇÓÉnameºÍvalue×é³ÉµÄ£¬
valueÖ»½ÓÊÜ×Ö·û´®£¨·Ç×Ö·û´®ÀàÐÍÒªÏÈת»»³É×Ö·û´®²ÅÐУ©¡£ÔÚ¹¹ÔìFieldʱ»¹
ÒªÖ¸¶¨
Ïà¹ØÎĵµ£º
1.Duplicated Code
´úÂëÖظ´¼¸ºõÊÇ×î³£¼ûµÄÒìζÁË¡£ËûÒ²ÊÇRefactoringµÄÖ÷ҪĿ±êÖ®Ò»¡£´úÂëÖظ´ÍùÍùÀ´×ÔÓÚcopy-and-pasteµÄ±à³Ì·ç¸ñ¡£ÓëËûÏà¶ÔÓ¦OAOOÊÇÒ»¸öºÃϵͳµÄÖØÒª±êÖ¾¡£
2.Long method
ËüÊÇ´«Í³½á¹¹»¯µÄ“ÒŶ¾”¡£Ò»¸ö·½·¨Ó¦µ±¾ßÓÐ×ÔÎÒ¶ÀÁ¢µÄÒâͼ£¬²»Òª°Ñ¼¸¸öÒâͼ·ÅÔÚÒ»Æð¡£ ......
ÔÚͨ¶ÁjdkÔ´´úÂëµÄʱºò·¢ÏÖÐí¶àjava·½·¨Ç°¶¼ÓÐnative¹Ø¼ü×ÖÐÞÊΣ¬×îºóµÃÖªnativeÊÇÓëC++ÁªºÏ¿ª·¢µÄʱºòÓõģ¬java×Ô¼º¿ª·¢²»Óá£
ʹÓÃnative¹Ø¼ü×Ö˵Ã÷Õâ¸ö·½·¨ÊÇÔÉúº¯Êý£¬Ò²¾ÍÊÇÕâ¸ö·½·¨ÊÇÓÃC/C++ÓïÑÔʵÏֵģ¬²¢ÇÒ±»±àÒë³ÉÁËDLL£¬ÓÉjavaÈ¥µ÷Óá£ÕâЩº¯Êý ......
ÒëÕß×¢ :Äã¿ÉÄÜ»á¾õµÃJavaºÜ¼òµ¥£¬ObjectµÄequalsʵÏÖÒ²»á·Ç³£¼òµ¥£¬µ«ÊÇÊÂʵ²¢²»ÊÇÄãÏëÏóµÄÕâÑù£¬ÄÍÐĵĶÁÍê±¾ÎÄ£¬Äã»á·¢ÏÖÄã¶ÔJavaÁ˽âµÄÊÇÈç´ËµÄÉÙ¡£Èç¹ûÕâƪÎÄÕÂÊÇÒ»·ÝJava³ÌÐòÔ±µÄÈëÖ°±ÊÊÔ£¬ÄÇô²»ÖªµÀÓжàÉÙÈË»áµôÂäµ½ÕâÑùµÄÏÝÚåÖС£ÔÎÄת×Ôhttp://www.artima.com/lejava/articles/equality.html Èýλ×÷Õ߶¼ÊDz»Í¬Áì ......
BlockingQueueÊÇÒ»¸ö½Ó¿Ú£¬Ëü´ÓQueue¼Ì³Ð¶øÀ´£¬
°üº¬ÁËQueueµÄËùÓй¦ÄÜ£¬²¢ÔÚQueueµÄ»ù´¡ÉÏÌṩÁË2¸öÐµĹ¦ÄÜ£º
1. ¼ìË÷ÔªËØʱµÈ´ý¶ÓÁбäΪ·Ç¿Õ
2. ´æ´¢ÔªËØʱµÈ´ý¿Õ¼ä±äµÃ¿ÉÓá£
ÏÂÃæ³Â¼Ò»Ð©JDKÎĵµÖйØÓÚBlockingQueueµÄ½éÉÜ£º
BlockingQueue ¿ÉÒÔÊÇÏÞ¶¨ÈÝÁ¿µÄ¡£ËüÔ ......
ÎÒ½ñÌìѧϰÁËÐìÀÏʦ½«µÄhibernate¿ò¼Ü֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
¼¯ºÏÊôÐÔ´óÖ·ÖΪ¶þÖÖ£º
µ¥´¿µÄ¼¯ºÏÊôÐÔ£¬ÏñList,Set»òÊý×éµÈ¼¯ºÏÊôÐÔ¡£
2,Map¼¯ºÏÊôÐÔ£¬Ã¿¸öÊôÐÔÖµ¶àÓÐÏà¶ÔÓ¦µÄKeyÓ³Éä¡£
&nb ......