JAKARTAPROJECT
JAKARTA TIPJSP TIPJSP Áú¹®&´äº¯DATABASE TIPJAVASCRIPT TIPWEBHACKING TIP±âŸ TIP
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ® ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
Apache Lucene "µ¥¸ð ½ÇÇà ¹× ºÐ¼®"Æí
GoodBug
À̹ÌÁö ½½¶óÀÌ´õ º¸±â

 

 

 

 

 

I. Welcom to Lucene !

 

  Lucene Àº ÀÚ¹Ù·Î ±¸ÇöµÈ °í¼º´ÉÀÇ Ç®ÅؽºÆ® °Ë»ö¿£ÁøÀÔ´Ï´Ù

  Lucene ÀÌ Á¦°øÇÏ´Â API¸¦ »ç¿ëÇÏ¿© °­·ÂÇÏ°í À¯¿¬ÇÑ °Ë»ö±â´ÉÀ» ¾îÇø®ÄÉÀ̼ǿ¡ ¼Õ½±°Ô Ãß°¡ÇÒ ¼ö ÀÖ½À´Ï´Ù

  LuceneÀº 2005³â 2¿ù¿¡ Apache top-level ·Î µî±ÞÀÌ »ó½ÂÇÏ¿´°í

  ¼­ºê ÇÁ·ÎÁ§Æ®ÀÎ Nutch ¶ÇÇÑ 2005³â 6¿ù¿¡ Apache Incubator¸¦ Á¹¾÷ÇÏ¿´½À´Ï´Ù

 

  Lucene´Â ´ÙÀ½ 3°¡Áö software¸¦ Æ÷ÇÔÇÏ°í ÀÖ½À´Ï´Ù

  ¨ç Lucene java : LuceneÀÇ ÇÙ½É ºÎºÐÀ¸·Î indexing °ú search ±¸Çö ¿µ¿ªÀÔ´Ï´Ù

  ¨è Nutch : web search applicationÀ» Áö¿øÇÕ´Ï´Ù (À̽´!)

                 mp3, pdf, ms µî ´Ù¾çÇÑ ¹®¼­¸¦ °Ë»öÇÒ¼ö ÀÖµµ·Ï Á¦°øÇØ ÁÖÁö¸¸

                 ¾ÆÁ÷±îÁö´Â 0.6 ¹öÁ¯À̳׿ä

  ¨é Lucene4c :  LuceneÀÇ C ±â¹ÝÀÇ °Ë»ö¿£ÁøÀÔ´Ï´Ù ¾ÆÁ÷±îÁø Incubator¿¡ ÀÖ±º¿ä

 

  À̹ø °­Á¿¡¼­´Â Lucene java ÇÔ µÚº­º¸°í À¥¿¡´Ù LuceneÀ» ´Þ¾Æº¾½Ã´Ù ^^

 

  °­Á ÁøÇà ¼ø¼­´Â "µ¥¸ðI ÇÁ·Î±×·¥(¾îÇø® ÄÉÀ̼Ç) -> µ¥¸ðII ÇÁ·Î±×·¥(À¥ ¾îÇø®ÄÉÀ̼Ç) -> µ¥¸ðII ÇÁ·Î±×·¥ ¼öÁ¤" ¼øÀ¸·Î °©´Ï´Ù

 

  ps. Çѱ۰˻öÀÌ °¡´ÉÇÏÁö¸¸ ÇÑ±Û ÇüÅÂ¼Ò ºÐ¼®À» ¾ÆÁ÷±îÁö´Â Áö¿øÇÏÁö ¾Ê±â ¶§¹®¿¡

       ÇѱÛÀº ´Ü¼ø°Ë»öÀ¸·Î ¸¸Á·ÇØ¾ß ÇÕ´Ï´Ù.

       ÇÏÁö¸¸ ¿µ¹®Àº ±â¶ËÂ÷°Ô Àߵ˴ϴÙ

 

 

II. Download

 

  lucene ´Ù¿î·Îµå

  http://www.apache.org/dyn/closer.cgi/jakarta/lucene/binaries/

 

  Âü°í »çÀÌÆ®

  http://lucene.apache.org/

  http://lucene.apache.org/java/docs/api/index.html

  http://lucene.apache.org/java/docs/index.html

  http://today.java.net/pub/a/today/2003/11/07/QueryParserRules.html

  http://www-128.ibm.com/developerworks/library/j-lucene/

  http://www.onjava.com/pub/a/onjava/2003/03/05/lucene.html

 

 

 

III. ¼³Ä¡

 

  ±×·³ ÀÌÁ¦ Lucene¿¡ Çѹø ºüÁ® º¾½Ã´Ù~!

  ¨ç ´Ù¿î¹ÞÀº lucene-1.4.3.zip ÆÄÀÏÀ» C:\¿¡ ¾ÐÃàÀ» DZ´Ï´Ù

 


 

  ¨è ¾ÐÃàÀ» Ç®¸é lucene-1.4.3.jar¿Í lucene-demos-1.4.3.jar ÆÄÀÏÀ» Ŭ·¡½º Æнº¿¡ °Ì´Ï´Ù

 

 

C:\Documents and Settings\Administrator>cd c:\

C:\>cd lu*

C:\lucene-1.4.3>set classpath=C:\lucene-1.4.3\lucene-1.4.3.jar;C:\lucene-1.4.3\lucene-demos-1.4.3.jar

 

C:\lucene-1.4.3>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
ANT_HOME=C:\java\Jeus42\lib\etc\ant
APPDATA=C:\Documents and Settings\Administrator\Application Data
CLASSPATH=C:\lucene-1.4.3\lucene-1.4.3.jar;C:\lucene-1.4.3\lucene-demos-1.4.3.jar

...

 

 

  "set" ¸í·ÉÀ¸·Î È®ÀÎÇÕ´Ï´Ù

  ¼³Ä¡ ³¡ ~

 

 

IV. µ¥¸ðI ½ÇÇàÇϱâ

 

  Lucene µ¥¸ð¿¡´Â µÎ°¡Áö µ¥¸ð°¡ ÀÖ½À´Ï´Ù

  Çϳª´Â ÀϹÝÀûÀÎ À妽Ì, ¹× °Ë»öÀÌ°í ´Ù¸¥ Çϳª´Â À¥¿¡¼­ »ç¿ëÇϱâ À§ÇÑ Àε¦½Ì ¹× À¥°Ë»öÀÔ´Ï´Ù

 

1) µ¥¸ðI ½ÇÇà


¸ÕÀú ³×À̹ö³ª ¾ßÈÄ°°Àº À¥ °Ë»ö¿£ÁøÀ» »ý°¢ÇØ º¾½Ã´Ù
¼öµµ¾øÀÌ ¸¹Àº ¹®¼­µéÀÌ ¾î¶»°Ô Çؼ­ ±×·¸°Ô ºü¸± °Ë»öµÉ±î¿ä?
¹Ù·Î °Ë»ö Àüó¸® ÀÛ¾÷À» Çϱ⠶§¹®ÀÔ´Ï´Ù
¿¹¸¦µé¾î °£´ÜÇÏ°Ô º¸ÀÚ¸é "love"¶ó´Â ´Ü¾î´Â A¹®¼­, B¹®¼­, C¹®¼­¿¡ Æ÷ÇԵǾî ÀÖ´Ù¶ó´Â Á¤º¸¸¦ ¹Ì¸® ¸¸µé¾î µÎ´Â °ÍÀÔ´Ï´Ù
Áï À妽º¸¦ ¸¸µé¾î µÎ´Â °ÍÀÌÁö¿ä
±×¸®°í À¥·Îº¿µéÀÌ ¹®¼­¸¦ ¼öÁýÇØ¿À¸é Ãß°¡µÈ ¹®¼­µé¿¡ ´ëÇØ ÇÏ·ç¿¡ ¸î¹ø¾¿ ¹èÄ¡ÀÛ¾÷À¸·Î À妽º¸¦ Ãß°¡ÇØ ÁÖ°ÚÁö¿ä
°á°úÀûÀ¸·Î "love" °Ë»ö½Ã À妽º Á¤º¸¸¦ µÚÁ®¼­ A¹®¼­, B¹®¼­, C¹®¼­ÀÇ °á°ú¸¦ º¸¿©ÁÖ´Â °Ì´Ï´Ù

 

luceneµµ ¸¶Âù°¡Áö ÀÔ´Ï´Ù À妽º¸¦ ¸ÕÀú ¸¸µé¾î ÁÖ¾î¾ß ÇÕ´Ï´Ù
¸ÕÀú ÀÏ´Ü µ¥¸ðÇÁ·Î±×·¥À» ÀÌ¿ëÇÏ¿© À妽º¸¦ ¸¸µé¾î º¸°í À̸¦ ÀÌ¿ëÇÏ¿© °Ë»öÇØ º¾½Ã´Ù
³»ºÎ ÄÚµùÀº ÀÏ´Ü ½ÇÇà ÀÌÈÄ¿¡ »ìÆ캾½Ã´Ù ^_^ (´«¿¡ ¸ÕÀú º¸¿©¾ß ¸Ö Çصµ ÀßµÇÁÕ)

 

C:\lucene-1.4.3\src\ ´Â µ¥¸ðÀ» À§ÇÑ ÀÚ¹Ù¼Ò½º ÆÄÀÏÀÔ´Ï´Ù


 

¨ç À妽º »ý¼ºÇϱâ
´ÙÀ½ ¸í·ÉÀ¸·Î À妽º¸¦ »ý¼ºÇØ º¾½Ã´Ù
À妽º »ý¼º ¾îÇø®ÄÉÀ̼ÇÀº IndexFiles.java À̸ç ÆĶó¹ÌÅÍ´Â À妽º¸¦ ¸¸µé ¼Ò½ºÆÄÀϵé(°Ë»ö´ë»óÆÄÀϵé) ÀÔ´Ï´Ù
¿©±â¼­´Â luceneÀÇ document¸¦ index ó¸®ÇØ º¸°Ú½À´Ï´Ù

 

C:\lucene-1.4.3>
C:\lucene-1.4.3>java org.apache.lucene.demo.IndexFiles C:\lucene-1.4.3\docs
adding C:\lucene-1.4.3\docs\api\allclasses-frame.html
adding C:\lucene-1.4.3\docs\api\allclasses-noframe.html
adding C:\lucene-1.4.3\docs\api\constant-values.html
adding C:\lucene-1.4.3\docs\api\deprecated-list.html
adding C:\lucene-1.4.3\docs\api\help-doc.html
adding C:\lucene-1.4.3\docs\api\index-all.html
adding C:\lucene-1.4.3\docs\api\index.html
adding C:\lucene-1.4.3\docs\api\org\apache\lucene\analysis\Analyzer.html
...
18500 total milliseconds
C:\lucene-1.4.3>

 

¾ßÈ£~ À妽º°¡ »ý¼ºµÇ¾ú½À´Ï´Ù



C:\lucene-1.4.3\index Ç®´õ¸¦º¸¸é ´ÙÀ½ ÆÄÀϵéÀÌ »ý¼ºµÈ °ÍÀ» ¾Ë¼öÀÖ½À´Ï´Ù

 

¨è °Ë»öÇϱâ
°Ë»ö ¾îÇø®ÄÉÀ̼ÇÀº SearchFiles.java À̸砽ÇÇà ÈÄ Query: ¿¡ °Ë»öÇÒ ´Ü¾î¸¦ ÀÔ·ÂÇØ º¾½Ã´Ù

C:\lucene-1.4.3>
C:\lucene-1.4.3>java org.apache.lucene.demo.SearchFiles
Query: lucene
Searching for: lucene
324 total matching documents
0. C:\lucene-1.4.3\docs\api\allclasses-frame.html
1. C:\lucene-1.4.3\docs\api\allclasses-noframe.html
2. C:\lucene-1.4.3\docs\api\index-all.html
3. C:\lucene-1.4.3\docs\api\overview-frame.html
4. C:\lucene-1.4.3\docs\api\overview-tree.html
5. C:\lucene-1.4.3\docs\api\org\apache\lucene\queryParser\MultiFieldQueryParser.html
6. C:\lucene-1.4.3\docs\lucene-sandbox\index.html
7. C:\lucene-1.4.3\docs\resources.html
8. C:\lucene-1.4.3\docs\api\org\apache\lucene\search\class-use\Query.html
9. C:\lucene-1.4.3\docs\api\org\apache\lucene\index\class-use\Term.html
more (y/n) ?

 

¿Í~ ¼º°ø! ¾öû ºü¸¨´Ï´Ù!!

°Ë»ö°á°ú°¡ 10°³¾¿ ¸®½ºÆÃµÇ¸ç ´ÙÀ½ ¸®½ºÆ®´Â y¹öÆ°À» Ŭ¸¯ÇÏ¿© Á¶È¸ ÇÒ¼ö ÀÖ½À´Ï´Ù

 

 

2) µ¥¸ðI Àε¦½Ì ÄÚµå ºÐ¼®

ÀÌ µ¥¸ð ÇÁ·Î±×·¥Àº °¡Àå ±âº»ÀÌ µÇ´Â ÇÁ·Î±×·¥À¸·Î ÇÙ½É ÄÚµù¸¸ µÇ¾î ÀÖÀ¸´Ï luceneÀ» »ç¿ëÇϱâ À§Çؼ­´Â ²À ¾Ë¾Æ µÎ¾î¾ß ÇÕ´Ï´Ù

 

¨ç Analyzer ¼±ÅÃ

Analyer ´Â ¹®¼­¸¦ Àε¦½Ì Çϰųª °Ë»öÇÒ¶§ ÇÙ½ÉÀÌ µÇ´Â ¿ä¼Ò·Î¼­, ÅؽºÆ®¸¦ ÆĽÌÇÒ ¶§ »ç¿ëÇÕ´Ï´Ù AnalyzerÀÇ Á¾·ù¿¡´Â ´ÙÀ½ ¸î°¡Áö µéÀÌ ÀÖ½À´Ï´Ù

 

SimpleAnalyzer

  non-letters ¸¦ ±âÁØÀ¸·Î ¹®ÀÚ¸¦ ÆĽÌÇÕ´Ï´Ù
  non-letters´Â java.lang.Character.isLetter()¿¡ ÀÇÇØ Á¤ÀÇµÈ °ÍÀ» »ç¿ëÇÕ´Ï´Ù
  ÀÌ Analyzer´Â ´ëºÎºÐÀÇ À¯·´±Ç ¾ð¾î¿¡ Àû´çÇÏ¸ç ¾Æ½Ã¾Æ±Ç ¾ð¾î¿¡´Â terrible À̶ó°í µÇ¾î ÀÖ±º¿ä -_-;
  ´ë¼Ò¹®ÀÚ ±¸ºÐ ¾ÈÇÕ´Ï´Ù

 

StopAnalyzer

  ±âº»ÀûÀ¸·Î SimpleAnalyzer¿Í °°À¸³ª StopFilter¸¦ µÎ¾î StopWord¸¦ Á¦°ÅÇÑ ÈÄ ºÐ¼®ÇÕ´Ï´Ù
  StopWord¶õ ÀϹÝÀûÀ¸·Î °Ë»ö½Ã À¯¿ëÇÏÁö ¾Ê´Â ´Ü¾îµéÀ» ¸»ÇÕ´Ï´Ù
  (a,an,and,are,as,at,be,but,by,for,if,in,into,is,it,no,not,of,on,or,s,such,t,that,the,their,then,there,these,they,this,to,was,will,with) ¿ª½Ã³ª ´ë¼Ò¹®ÀÚ ±¸ºÐ ¾ÈÇÕ´Ï´Ù

 

StandardAnalyzer 

  ´ëºÎºÐ À¯·Æ±Ç ¾ð¾îµé¿¡ ÃÖÀûÈ­ µÇ¾îÀÖ´Â Analyzer ÀÔ´Ï´Ù
  StopFilter¸¦ »ç¿ëÇÏ¸ç ´ë¼Ò¹®ÀÚ ±¸ºÐ ¾ÈÇÕ´Ï´Ù

 

WhitespaceAnalyzer 

  whitespace, Áï °ø¹é¹®ÀÚ¸¦ °¡Áö°í text¸¦ ³ª´©´Â ¹æ½ÄÀÔ´Ï´Ù
  °¡Àå ±âº»ÀûÀ̸鼭µµ ¹«½ÄÇÑ ¹æ½ÄÀÔ´Ï´Ù
  ºÒÇàÈ÷µµ Çѱ۰˻öÀº ÀÌ WhitespaceAnalyzer ¸¸ °¡´ÉÇÏ¸ç ´ë¼Ò¹®ÀÚ ±¸ºÐ ÇÕ´Ï´Ù

  (¿Ö À̰͸¸ ´ë¼Ò¹®ÀÚ ±¸ºÐ ÇÏ³É -_-)

 

À̹ۿ¡µµ GermanAnalyzer, PerFieldAnalyzerWrapper, RussianAnalyzerµîÀÌ ÀÖÀ¸¸ç
À̸§¿¡¼­µµ ¾Ë¼öÀÖµíÀÌ ±×´ÙÁö Çѱ۰ú Ä£ÇÏÁö ¾ÊÀºµí ÇÕ´Ï´Ù -.-;;

 

¨è IndexWriter »ý¼º
ÀÚ ÀÌÁ¦ Analyer¸¦ ¼±ÅÃÇßÀ¸¸é IndexWriter¸¦ »ý¼ºÇÏ¿© Index¸¦ ¸¸µé¾îº¾½Ã´Ù

 

IndexWriter writer = new IndexWriter("index", new StandardAnalyzer(), true);

 

ù¹ø° ÆĶó¹ÌÅÍ´Â index°¡ »ý¼ºµÉ À§Ä¡¸¦ ¸»Çϸç
µÎ¹ø° ÆĶó¹ÌÅÍ´Â ¼±ÅÃÇÑ Analyzer¸¦,
¼¼¹ø° ÆĶó¹ÌÅÍ´Â index¸¦ ÃʱâÈ­ ÇÏ¿© ´Ù½Ã »ý¼ºÇÒ°ÍÀÎÁö ¸»°ÍÀÎÁö¸¦ ¸»ÇÕ´Ï´Ù
Áï Ãß°¡/»èÁ¦¸¸ ÇÒ °ÍÀÎÁö(false) »õ·Î ¸¸µé°ÍÀÎÁö(true)¸¦ ³ªÅ¸³À´Ï´Ù
¹®¼­°¡ ¸¹À»°æ¿ì ¸Å¹ø »õ·Î ¸¸µé¼ö ¾øÀ¸¸ç,
¶ÇÇÑ ¸¸¾à ¸î°³ÀÇ ¹®¼­¸¸ º¯°æµÇ¾ú´Âµ¥ ¸ðµÎ ´Ù½Ã À妽º¸¦ ¸¸µé¼ö´Â ¾ø±â ¶§¹®ÀÔ´Ï´Ù (½Ã°£ »ó´çÈ÷ °É¸² --)


¨é Index¿¡ document Ãß°¡
´ÙÀ½À¸·Î ¼Ò½º µð·ºÅ丮(°Ë»ö´ë»ó ¹®¼­µé)ÀÇ ÆÄÀϵéÀ» Àо¸ç Analyzer¿¡ ÀÇÇØ ÆÄ½ÌµÈ ¹®¼­ Á¤º¸¸¦ À妽º¿¡ Ãß°¡ÇÕ´Ï´Ù

 

writer.addDocument(FileDocument.Document(file));

 

¨ê index optimize
¸¶Áö¸·À¸·Î À妽ÌÇÑ Á¤º¸¸¦ ÇϳªÀÇ ÆÄÀÏ·Î merge ÇÕ´Ï´Ù
Áï °Ë»ö¿¡ ÀûÇÕÇϵµ·Ï ÆÄÀÏÀ» Çϳª·Î ÇÕÄ¡´Â °Ì´Ï´Ù

 

writer.optimize();

 

¨ë index close

»ç¿ëÈÄ ¹Þµå½Ã close ÇսôÙ!

 

writer.close();

 

³¡~ °£´ÜÇÏÁÒ?

ÀÌÁ¦ Àüü ¼Ò½º¸¦ »ìÆ캾½Ã´Ù

¼Ò½º´Â C:\lucene-1.4.3\src\demo\org\apache\lucene\demo ¿¡ ÀÖ½À´Ï´Ù

 

org.apache.lucene.demo.IndexFiles.java

 

class IndexFiles {

 

  public static void main(String[] args) throws IOException {

    String usage = "java " + IndexFiles.class + " <root_directory>";
   
    // ÆĶó¹ÌÅÍ(¼Ò½ºµð·ºÅ丮)¸¦ ÀÔ·ÂÇÏÁö ¾Ê¾Ò´Ù¸é »ç¿ë¹ýÀ» Ãâ·ÂÇØ ÁÝ´Ï´Ù
    if (args.length == 0) {
      System.err.println("Usage: " + usage);
      System.exit(1);
    }

    Date start = new Date();
    try {
   
      // ¼±ÅÃÇÑ Analyzer¸¦ ÀÌ¿ëÇÏ¿© IndexWriter¸¦ »ý¼ºÇÕ´Ï´Ù
      IndexWriter writer = new IndexWriter("index", new StandardAnalyzer(), true);
     
      // ¼Ò½ºµð·ºÅ丮¸¦ µðºñ°¡¸ç ¹®¼­¸¦ ÆĽÌÇÏ¿© À妽º¿¡ Ãß°¡ÇÏ´Â Àç±ÍÇÔ¼ö
      indexDocs(writer, new File(args[0]));

      // À妽ÌÇÑ ¿©·¯ segmentµéÀ» °Ë»ö¿¡ ¾Ë¸Âµµ·Ï Çϳª·Î ÇÕÄ¡´Â ÀÛ¾÷
      writer.optimize();
     
      // ¹Ýµå½Ã close()
      writer.close();

      Date end = new Date();

      // Àε¦½Ì ó¸®½Ã°£ Ãâ·Â
      System.out.print(end.getTime() - start.getTime());
      System.out.println(" total milliseconds");

    } catch (IOException e) {
      System.out.println(" caught a " + e.getClass() +
       "\n with message: " + e.getMessage());
    }
  }

 

  // ¼Ò½º ÆÄÀϵéÀ» Àо¸ç ÆĽÌÇÏ¿© À妽º¿¡ Ãß°¡ÇÏ´Â Àç±ÍÇÔ¼ö
  public static void indexDocs(IndexWriter writer, File file)
    throws IOException {

 

    if (file.canRead()) {
      if (file.isDirectory()) {
        String[] files = file.list();

 

        if (files != null) {
          for (int i = 0; i < files.length; i++) {
            // ÀÚ±âÀÚ½ÅÀ» È£Ãâ
            indexDocs(writer, new File(file, files[i]));
          }
        }
      } else {
        System.out.println("adding " + file);
        try {
          // ¹®¼­¸¦ À妽º¿¡ Ãß°¡

          // FileDocument´Â ÇØ´ç fileÀÇ Á¤º¸¸¦ ÆĽÌÇØÁÜ
          writer.addDocument(FileDocument.Document(file));
        }
       
        // À©µµ¿¡¼­ temporary fileseµîÀÌ access denied·Î  exceptionÀÌ ¹ß»ýÇÒ ¼ö ÀÖÀ½
        catch (FileNotFoundException fnfe) {
          ;
        }
      }
    }
  }
}

 

 

3) µ¥¸ðI °Ë»ö ÄÚµåºÐ¼®
°Ë»öÀº À妽º¸¦ ¸¸µå´Â Äڵ庸´Ù ÈξÀ ½±½À´Ï´Ù


¨ç IndexSearcher »ý¼º
½ÇÁúÀûÀ¸·Î °Ë»öÀ» ´ã´çÇÒ IndexSearcher¸¦ »ý¼ºÇØ º¾½Ã´Ù
ÆĶó¹ÌÅͷδ index°¡ »ý¼ºµÇ¾îÀÖ´Â À§Ä¡¸¦ ÀÔ·ÂÇÕ´Ï´Ù

 

Searcher searcher = new IndexSearcher("index");

 

¨è Query »ý¼º
Query´Â ÁúÀÇ ¹®ÀÚ¿­À» ÆĽÌÇØ ÁÝ´Ï´Ù (Áï AND,OR,NOT,!,-µîÀÇ ³í¸®¿¬»êÀ̳ª ¿ÍÀϵåÄ«µå *,?µîÀ» ÆĽÌÇÕ´Ï´Ù)

 

Query query = QueryParser.parse(line, "contents", analyzer);

 

ù¹ø° ÆĶó¹ÌÅÍ´Â ÁúÀǸ¦,
µÎ¹ø° ÆĶó¹ÌÅÍ´Â °Ë»ö Çʵ带,
¼¼¹ø° ÆĶó¹ÌÅÍ´Â À妽º¸¦ ¸¸µç Analyzer¿Í µ¿ÀÏÇÑ Analyzer¸¦ ÀÔ·ÂÇØ Áà¾ß ÇÕ´Ï´Ù

 

¨é °Ë»ö ¹× °Ë»öÇÑ °á°ú ÀúÀå

ÆÄ½ÌµÈ Äõ¸®¸¦ °¡Áö°í °Ë»öÇÏ¿© ±× °á°ú°ªÀ» ¹Ýȯ ¹Þ½À´Ï´Ù

 

Hits hits = searcher.search(query);

 

¹ÝȯµÈ Hits Ŭ·¡½º´Â ¼øÀ§°¡ ¸Å°ÜÁø ¹®¼­µé·Î °Ë»ö°á°ú¸¦ ÀúÀåÇÏ°í À¯ÁöÇÕ´Ï´Ù

 

¨ê IndexSearcher close
°Ë»öÀÌ ³¡³µÀ¸¸é ´Ý¾ÆÁݽôÙ

 

searcher.close();

 

Àüü ¼Ò½º¸¦ »ìÆ캾½Ã´Ù

 

org.apache.lucene.demo.SearchFiles.java

class SearchFiles {


  public static void main(String[] args) {
    try {


      // index Æú´õ¸¦ ÆĶó¹ÌÅÍ·Î ³Ñ°Ü IndexSearcher¸¦ »ý¼ºÇÕ´Ï´Ù
      Searcher searcher = new IndexSearcher("index");
     
      // »ý¼ºµÈ index¿Í µ¿ÀÏÇÑ Analyzer¸¦ »ý¼ºÇÏ¿© ³Ñ°ÜÁÝ´Ï´Ù
      Analyzer analyzer = new StandardAnalyzer();

 

      // °Ë»ö¾î¸¦ ÀԷ¹ޱâ À§ÇÑ reader ÀÔ´Ï´Ù
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));


      while (true) {
        System.out.print("Query: ");
        String line = in.readLine();
       
        if (line.length() == -1)
          break;

 

        // ÀԷ¹ÞÀº ÁúÀǸ¦ ÆĽÌÇÕ´Ï´Ù
        Query query = QueryParser.parse(line, "contents", analyzer);
        System.out.println("Searching for: " + query.toString("contents"));

 

        // ÆÎ½ÌµÈ ÁúÀÇ·Î °Ë»öÀ» ÇÕ´Ï´Ù       
        Hits hits = searcher.search(query);
        System.out.println(hits.length() + " total matching documents");
       
        // °Ë»ö °á°ú ¸ñ·ÏÀ» 10°³¾¿ º¸¿©ÁÝ´Ï´Ù
        final int HITS_PER_PAGE = 10;
        for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
          int end = Math.min(hits.length(), start + HITS_PER_PAGE);
          for (int i = start; i < end; i++) {

 

            // °Ë»ö °á°ú·Î ºÎÅÍ ¹®¼­¸¦ °¡Á®¿É´Ï´Ù
            Document doc = hits.doc(i);

            // ¹®¼­Á¤º¸¸¦ Ãâ·ÂÇÕ´Ï´Ù

            String path = doc.get("path");
            if (path != null) {
                  System.out.println(i + ". " + path);
            } else {
                  String url = doc.get("url");
              if (url != null) {
                System.out.println(i + ". " + url);
                System.out.println("   - " + doc.get("title"));
              } else {
                System.out.println(i + ". " + "No path nor URL for this document");
              }
            }
          }

 

          if (hits.length() > end) {
            System.out.print("more (y/n) ? ");
            line = in.readLine();
            if (line.length() == 0 || line.charAt(0) == 'n')
              break;
          }
        }
      }
     
      searcher.close();
       
    } catch (Exception e) {
      System.out.println(" caught a " + e.getClass() +
         "\n with message: " + e.getMessage());
    }
  }
}

 

 

V. ÁúÀÇ ¹®¹ý

ÁúÀÇ ¹®¹ý¿¡ ´ëÇØ ¾Ë¾Æº¾½Ã´Ù

 

¨ç A AND B

    A¿Í B°¡ ¸ðµÎ Æ÷ÇÔµÈ ¹®¼­¸¦ °Ë»öÇÑ´Ù

¨è A OR B

    AȤÀº B°¡ Æ÷ÇÔµÈ ¹®¼­¸¦ °Ë»öÇÑ´Ù

¨é A NOT B

    A´Â Æ÷ÇԵǰí B´Â Æ÷ÇÔµÇÁö ¾Ê´Â ¹®¼­¸¦ °Ë»öÇÑ´Ù

    A ! B, A - B¿Í µ¿ÀÏÇÏ´Ù

¨ê +A OR B

    A OR B¿¡¼­ A´Â ¹Þµå½Ã Æ÷ÇÔµÈ ¹®¼­¸¦ °Ë»öÇÑ´Ù

¨ë A*

    A·Î ½ÃÀÛÇÏ´Â ´Ü¾î°¡ ÀÖ´Â ¹®¼­¸¦ °Ë»öÇÑ´Ù

¨ì A?

    A·Î ½ÃÀÛÇÏ´Â µÎ±ÛÀÚÀÇ ´Ü¾î°¡ ÀÖ´Â ¹®¼­¸¦ °Ë»öÇÑ´Ù

¨í A~

    A¿Í ½ºÆ縵ÀÌ ºñ½ÁÇÑ ±ÛÀÚ¸¦ Áö´Ñ ´Ü¾î°¡ ÀÖ´Â ¹®¼­¸¦ °Ë»öÇÑ´Ù

¨î (A OR B) AND C

    ³í¸®¿¬»êÀÇ ±×·çÇÎ ¶ÇÇÑ Áö¿øÇÑ´Ù

 

AND, OR, NOTµîÀº ¹Ýµå½Ã ´ë¹®ÀÚ·Î ÀÔ·ÂÇØ¾ß Àνĵ˴ϴÙ

 

´ÙÀ½ ½Ã°£¿¡´Â µÎ¹ø° µ¥¸ð ÇÁ·Î±×·¥À» ½ÇÇà½ÃÄÑ º¸°í luceneÀ» À¥ ¾îÇø®ÄÉÀ̼ǿ¡ ´Þ¾Æ º¾½Ã´Ù~

 

=============================================

º»¹®¼­´Â ÀÚÀ¯·Ó°Ô ¹èÆ÷/º¹»ç ÇÒ¼ö ÀÖÁö¸¸

À̹®¼­ÀÇ ÀúÀÚ¿¡ ´ëÇÑ ¾ð±ÞÀ» »èÁ¦ÇÏ½Ã¸é ¾ÈµË´Ï´Ù

ÀúÀÚ : GoodBug (unicorn@jakartaproject.com)

ÃÖÃÊ : http://www.jakartaproject.com 

=============================================

2011-11-06 14:35:06
211.189.124.***

 

ÁÁÀº»ý°¢ ^^

8Á¡ (6¸í)
¾È³çÇϼ¼¿ä^_^ 1 ¹ðÁÖ¾º 2005-03-17
js, xmlÀ» ÀÌ¿ëÇÑ µ¿Àû·Îµù°¡´É Æ®¸® GoodBug 2005-03-25
lucene Apache Lucene "µ¥¸ð ½ÇÇà ¹× ºÐ¼®"Æí 4 Tag 1 GoodBug 2005-07-19
Ant-Contrib Tasks GoodBug 2006-02-04
Analyze Çϱâ GoodBug 2005-05-28
½ºÅ²¼³Á¤½Ã... Ãʺ¸»ç¿ëÀÚ 2005-03-30
[´äº¯] ½ºÅ²¼³Á¤½Ã... GoodBug 2005-03-30
µ¡±Û 4°³ | ÅÂ±× 1°³ | °ü·Ã±Ûº¸±â
ű×ÀÔ·Â
½±Ç¥(,)±¸ºÐÀ¸·Î Çѹø¿¡ ¿©·¯ ű׸¦ ÀÔ·ÂÇÒ¼ö ÀÖ½À´Ï´Ù
lucene (3)
rainyfact
(0) (0)
¤£^-^
61.98.191.*** 2005-08-02 10:20:40
¼ö½Ã¾Æ
(0) (0)
´ÙÀ½ÆíÀÌ ±â´ë µÇ³×¿ä~ ^^
58.151.244.*** 2005-08-02 14:39:06
±è
(0) (0)
À§¿¡ Æò°¡ good Àε¥ À߸ø Ŭ¸¯Ç߳׿ä. Á˼Û..^^ À¥ ¾îÇø®ÄÉÀ̼ÇÀº ¾ø´Â °Í °°³×¿ä? ²À ÀÐ°í ½ÍÀºµ¥, ºÎŹÇÕ´Ï´Ù.
211.49.109.*** 2006-02-20 20:40:41
±è
(0) (0)
+1 ÀÌ°í good ÀÌ°í -1dl bad ¿´±º¿ä. Á¦´ë·Î Ç߳׿ä. ¾Æ¹«Æ° ÀÚÁÖ ¹æ¹®Çؼ­ °øºÎ Á» ÇÒ °èȹÀÔ´Ï´Ù.
211.49.109.*** 2006-02-20 20:42:31
À̸§ ºñ¹Ð¹øÈ£
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ® ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
! ¹øÈ£ Á¦¸ñ ±Û¾´ÀÌ ÀÏÀÚ Á¶È¸
Hierarchy of the Apache Software Foundation GoodBug 2005-10-14 10,814
Jakarta Project °­Á °Ô½ÃÆÇÀÔ´Ï´Ù 8 GoodBug 2005-04-03 11,701
44 Log4J log4j¿¡¼­ e.printStackTrace() ¸Þ½ÃÁö¸¦ log¿¡ ³²±â´Â ¹æ¹ý 1 kaiser 2008-10-22 17,613
43 DBUtils DBUtils¿¡¼­ Clob »ç¿ëÇϱâ 3 1 GoodBug 2007-08-28 10,633
42 Spring Spring ¼³Á¤ ÆÄÀÏ ·Îµù 1 GoodBug 2007-07-16 11,317
41 POI POIÀÇ HSLF¸¦ ÀÌ¿ëÇÏ¿© PowerPoint ¹®¼­¸¦ ÀоÀÚ 2 GoodBug 2007-05-28 14,910
40 POI POIÀÇ HWPF¸¦ ÀÌ¿ëÇÏ¿© MS WORD¹®¼­¸¦ ÀоÀÚ 2 GoodBug 2007-05-28 16,839
39 Validator Validator ¼Ó¼ºµé 1 GoodBug 2007-05-11 10,404
38 dd Commons-Fileupload 1.2 1 2 GoodBug 2007-04-23 15,345
37 Apache Apache2 + Tomcat5.5 + mod_jk 4 ¹ÙÀÌ·¯½ºô¸国 2007-01-29 11,066
36 DBUtils DBUtils¿¡¼­ number ŸÀÔÀÇ Ä÷³ÀÌ intÇüÀ¸·Î ¾È³Ñ¾î¿Ã¶§.. 3 1 GoodBug 2006-06-28 10,755
35 ÈìÈì À§ÇèÇÑ static Logger Çʵå... 2 1 ¼­¿¬¾Æºü 2006-03-16 10,113
34 Installing Tomcat with commons-daemon (jsvc) GoodBug 2006-01-08 9,067
33 commons Commons DbUtils ¸î°¡Áö ¿¹Á¦ 3 2 GoodBug 2005-11-17 15,221
32 commons Jakarta Commons Net ¿¡¼­ FTP »ç¿ë½Ã ¸ñ·ÏÀÌ ¾Èº¸ÀÏ °æ¿ì 2 GoodBug 2005-11-15 21,776
31 listFiles() ¿¡¼­ null À» ¹Ýȯ ÃßÀû.. ½Å¸¸µÎ 2008-11-11 11,866
30 commons ¸ñ·ÏÀÌ ¾Èº¸ÀÏ °æ¿ì ÇØ°á±â Iź 1 2 GoodBug 2005-12-23 15,932
29 POI POI·Î ¿¢¼¿ÆÄÀÏ ÀÐÀ»¶§, Invalid header signature ¿¡·¯ 1 GoodBug 2005-11-12 16,540
28 log4j log4j, JSP¿¡¼­ ¿øÇÏ´Â Appender °ñ¶ó¾²±â 1 GoodBug 2005-11-07 13,894
27 commons Commons-Email~ 7 2 GoodBug 2005-10-13 17,860
copyright 2005-2024 by Unicorn