lucene

来源:互联网 发布:js获取s:property 编辑:程序博客网 时间:2024/06/08 05:39

 

    理论参考:http://lianj-lee.iteye.com/category/69005?show_full=true

    Lucene3.0对数据库建立索引:http://269181927.iteye.com/blog/789779

 

1. 所需要的文件(见附件)

 

    依赖包:

    lucene-core-2.4.0.jar                   lucene工具包

    lucene-highlighter-2.4.0.jar          高亮显示工具包

    IKAnalyzer2.0.2OBF.jar                分词工具(支持字典分词)

    mysql-connector-java-5.0.3-bin    链接mysql驱动

 

    数据表:

    pd_ugc.sql(所在数据库为lucenetest)

 

    类文件:

    在附件index.rar和test.rar,解压后放入java工程中的src下即可

 

2. 为数据库建立增量索引

    参考网页:http://www.blogjava.net/laoding/articles/279230.html

Java代码  收藏代码
  1. package index;  
  2. //--------------------- Change Logs----------------------  
  3. // <p>@author zhiqiang.zhang Initial Created at 2010-12-23<p>  
  4. //-------------------------------------------------------  
  5. import java.io.BufferedReader;  
  6. import java.io.File;  
  7. import java.io.FileReader;  
  8. import java.io.FileWriter;  
  9. import java.io.IOException;  
  10. import java.io.PrintWriter;  
  11. import java.sql.Connection;  
  12. import java.sql.DriverManager;  
  13. import java.sql.ResultSet;  
  14. import java.sql.Statement;  
  15. import java.util.Date;  
  16.   
  17. import org.apache.lucene.analysis.Analyzer;  
  18. import org.apache.lucene.analysis.standard.StandardAnalyzer;  
  19. import org.apache.lucene.document.Document;  
  20. import org.apache.lucene.document.Field;  
  21. import org.apache.lucene.index.IndexWriter;  
  22.   
  23. //增量索引  
  24. /* 
  25.  * 实现思路:首次查询数据库表所有记录,对每条记录建立索引,并将最后一条记录的id存储到storeId.txt文件中 
  26.  *         当新插入一条记录时,再建立索引时不必再对所有数据重新建一遍索引, 
  27.  *         可根据存放在storeId.txt文件中的id查出新插入的数据,只对新增的数据新建索引,并把新增的索引追加到原来的索引文件中 
  28.  * */  
  29. public class IncrementIndex {  
  30.   
  31.     public static void main(String[] args) {  
  32.         try {  
  33.             IncrementIndex index = new IncrementIndex();  
  34.             String path = "E:\\workspace2\\Test\\lucene_test\\poiIdext";//索引文件的存放路径  
  35.             String storeIdPath = "E:\\workspace2\\Test\\lucene_test\\storeId.txt";//存储ID的路径  
  36.             String storeId = "";  
  37.             Date date1 = new Date();  
  38.             storeId = index.getStoreId(storeIdPath);  
  39.             ResultSet rs = index.getResult(storeId);  
  40.             System.out.println("开始建立索引。。。。");  
  41.             index.indexBuilding(path, storeIdPath, rs);  
  42.             Date date2 = new Date();  
  43.             System.out.println("耗时:"+(date2.getTime()-date1.getTime())+"ms");  
  44.             storeId = index.getStoreId(storeIdPath);  
  45.             System.out.println(storeId);//打印出这次存储起来的ID  
  46.         } catch (Exception e) {  
  47.             e.printStackTrace();  
  48.         }  
  49.     }  
  50.   
  51.     public static void buildIndex(String indexFile, String storeIdFile) {  
  52.         try {  
  53.             String path = indexFile;//索引文件的存放路径  
  54.             String storeIdPath = storeIdFile;//存储ID的路径  
  55.             String storeId = "";  
  56.             storeId = getStoreId(storeIdPath);  
  57.             ResultSet rs = getResult(storeId);  
  58.             indexBuilding(path, storeIdPath, rs);  
  59.             storeId = getStoreId(storeIdPath);  
  60.             System.out.println(storeId);//打印出这次存储起来的ID  
  61.         } catch (Exception e) {  
  62.             e.printStackTrace();  
  63.         }  
  64.     }  
  65.   
  66.     public static ResultSet getResult(String storeId) throws Exception {  
  67.         Class.forName("com.mysql.jdbc.Driver").newInstance();  
  68.         String url = "jdbc:mysql://localhost:3306/lucenetest";  
  69.         String userName = "root";  
  70.         String password = "****";  
  71.         Connection conn = DriverManager.getConnection(url, userName, password);  
  72.         Statement stmt = conn.createStatement();  
  73.         String sql = "select  * from pd_ugc";  
  74.         ResultSet rs = stmt.executeQuery(sql + " where id > '" + storeId + "'order by id");  
  75.         return rs;  
  76.     }  
  77.   
  78.     public static boolean indexBuilding(String path, String storeIdPath, ResultSet rs) {  
  79.         try {  
  80.             Analyzer luceneAnalyzer = new StandardAnalyzer();  
  81.             // 取得存储起来的ID,以判定是增量索引还是重新索引  
  82.             boolean isEmpty = true;  
  83.             try {  
  84.                 File file = new File(storeIdPath);  
  85.                 if (!file.exists()) {  
  86.                     file.createNewFile();  
  87.                 }  
  88.                 FileReader fr = new FileReader(storeIdPath);  
  89.                 BufferedReader br = new BufferedReader(fr);  
  90.                 if (br.readLine() != null) {  
  91.                     isEmpty = false;  
  92.                 }  
  93.                 br.close();  
  94.                 fr.close();  
  95.             } catch (IOException e) {  
  96.                 e.printStackTrace();  
  97.             }  
  98.             //isEmpty=false表示增量索引  
  99.             IndexWriter writer = new IndexWriter(path, luceneAnalyzer, isEmpty);  
  100.             String storeId = "";  
  101.             boolean indexFlag = false;  
  102.             String id;  
  103.             String name;  
  104.             String address;  
  105.             String citycode;  
  106.             while (rs.next()) {  
  107.                 id = rs.getInt("id") + "";  
  108.                 name = rs.getString("name");  
  109.                 address = rs.getString("address");  
  110.                 citycode = rs.getString("citycode");  
  111.                 writer.addDocument(Document(id, name, address, citycode));  
  112.                 storeId = id;//将拿到的id给storeId,这种拿法不合理,这里为了方便  
  113.                 indexFlag = true;  
  114.             }  
  115.             writer.optimize();  
  116.             writer.close();  
  117.             if (indexFlag) {  
  118.                 // 将最后一个的ID存到磁盘文件中  
  119.                 writeStoreId(storeIdPath, storeId);  
  120.             }  
  121.             return true;  
  122.         } catch (Exception e) {  
  123.             e.printStackTrace();  
  124.             System.out.println("出错了" + e.getClass() + "\n   错误信息为:   " + e.getMessage());  
  125.             return false;  
  126.         }  
  127.   
  128.     }  
  129.   
  130.     public static Document Document(String id, String name, String address, String citycode) {  
  131.         Document doc = new Document();  
  132.         doc.add(new Field("id", id, Field.Store.YES, Field.Index.TOKENIZED));  
  133.         doc.add(new Field("name", name, Field.Store.YES, Field.Index.TOKENIZED));//查询字段  
  134.         doc.add(new Field("address", address, Field.Store.YES, Field.Index.TOKENIZED));  
  135.         doc.add(new Field("citycode", citycode, Field.Store.YES, Field.Index.TOKENIZED));//查询字段  
  136.         return doc;  
  137.     }  
  138.   
  139.     // 取得存储在磁盘中的ID  
  140.     public static String getStoreId(String path) {  
  141.         String storeId = "";  
  142.         try {  
  143.             File file = new File(path);  
  144.             if (!file.exists()) {  
  145.                 file.createNewFile();  
  146.             }  
  147.             FileReader fr = new FileReader(path);  
  148.             BufferedReader br = new BufferedReader(fr);  
  149.             storeId = br.readLine();  
  150.             if (storeId == null || storeId == "") storeId = "0";  
  151.             br.close();  
  152.             fr.close();  
  153.         } catch (Exception e) {  
  154.             e.printStackTrace();  
  155.         }  
  156.         return storeId;  
  157.     }  
  158.   
  159.     // 将ID写入到磁盘文件中  
  160.     public static boolean writeStoreId(String path, String storeId) {  
  161.         boolean b = false;  
  162.         try {  
  163.             File file = new File(path);  
  164.             if (!file.exists()) {  
  165.                 file.createNewFile();  
  166.             }  
  167.             FileWriter fw = new FileWriter(path);  
  168.             PrintWriter out = new PrintWriter(fw);  
  169.             out.write(storeId);  
  170.             out.close();  
  171.             fw.close();  
  172.             b = true;  
  173.         } catch (IOException e) {  
  174.             e.printStackTrace();  
  175.         }  
  176.         return b;  
  177.     }  
  178. }  

 

3. 索引操作

Java代码  收藏代码
  1. package index;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.Reader;  
  5. import java.io.StringReader;  
  6. import java.util.ArrayList;  
  7. import java.util.Date;  
  8. import java.util.List;  
  9.   
  10. import org.apache.lucene.analysis.Analyzer;  
  11. import org.apache.lucene.analysis.StopFilter;  
  12. import org.apache.lucene.analysis.Token;  
  13. import org.apache.lucene.analysis.TokenStream;  
  14. import org.apache.lucene.analysis.standard.StandardAnalyzer;  
  15. import org.apache.lucene.document.Document;  
  16. import org.apache.lucene.index.CorruptIndexException;  
  17. import org.apache.lucene.index.IndexReader;  
  18. import org.apache.lucene.index.Term;  
  19. import org.apache.lucene.queryParser.MultiFieldQueryParser;  
  20. import org.apache.lucene.queryParser.ParseException;  
  21. import org.apache.lucene.queryParser.QueryParser;  
  22. import org.apache.lucene.search.BooleanClause;  
  23. import org.apache.lucene.search.BooleanQuery;  
  24. import org.apache.lucene.search.Hits;  
  25. import org.apache.lucene.search.IndexSearcher;  
  26. import org.apache.lucene.search.Query;  
  27. import org.apache.lucene.search.ScoreDoc;  
  28. import org.apache.lucene.search.TopDocCollector;  
  29. import org.apache.lucene.search.highlight.Highlighter;  
  30. import org.apache.lucene.search.highlight.QueryScorer;  
  31. import org.apache.lucene.search.highlight.SimpleFragmenter;  
  32. import org.apache.lucene.search.highlight.SimpleHTMLFormatter;  
  33. import org.mira.lucene.analysis.IK_CAnalyzer;  
  34.   
  35. public class IndexUtils {  
  36.   
  37.     //0. 创建增量索引  
  38.     public static void buildIndex(String indexFile, String storeIdFile) {  
  39.         IncrementIndex.buildIndex(indexFile, storeIdFile);  
  40.     }  
  41.   
  42.     //1. 单字段查询  
  43.     @SuppressWarnings("deprecation")  
  44.     public static List<IndexResult> queryByOneKey(IndexSearcher indexSearcher, String field,  
  45.             String key) {  
  46.         try {  
  47.             Date date1 = new Date();  
  48.             QueryParser queryParser = new QueryParser(field, new StandardAnalyzer());  
  49.             Query query = queryParser.parse(key);  
  50.             Hits hits = indexSearcher.search(query);  
  51.             Date date2 = new Date();  
  52.             System.out.println("耗时:" + (date2.getTime() - date1.getTime()) + "ms");  
  53.             List<IndexResult> list = new ArrayList<IndexResult>();  
  54.             for (int i = 0; i < hits.length(); i++) {  
  55.                 list.add(getIndexResult(hits.doc(i)));  
  56.             }  
  57.             return list;  
  58.         } catch (ParseException e) {  
  59.             e.printStackTrace();  
  60.         } catch (IOException e) {  
  61.             e.printStackTrace();  
  62.         }  
  63.         return null;  
  64.     }  
  65.   
  66.     //2. 多条件查询。这里实现的是and操作  
  67.     //注:要查询的字段必须是index的  
  68.     //即doc.add(new Field("pid", rs.getString("pid"), Field.Store.YES,Field.Index.TOKENIZED));     
  69.     @SuppressWarnings("deprecation")  
  70.     public static List<IndexResult> queryByMultiKeys(IndexSearcher indexSearcher, String[] fields,  
  71.             String[] keys) {  
  72.   
  73.         try {  
  74.             BooleanQuery m_BooleanQuery = new BooleanQuery();  
  75.             if (keys != null && keys.length > 0) {  
  76.                 for (int i = 0; i < keys.length; i++) {  
  77.                     QueryParser queryParser = new QueryParser(fields[i], new StandardAnalyzer());  
  78.                     Query query = queryParser.parse(keys[i]);  
  79.                     m_BooleanQuery.add(query, BooleanClause.Occur.MUST);//and操作  
  80.                 }  
  81.                 Hits hits = indexSearcher.search(m_BooleanQuery);  
  82.                 List<IndexResult> list = new ArrayList<IndexResult>();  
  83.                 for (int i = 0; i < hits.length(); i++) {  
  84.                     list.add(getIndexResult(hits.doc(i)));  
  85.                 }  
  86.                 return list;  
  87.             }  
  88.         } catch (ParseException e) {  
  89.             e.printStackTrace();  
  90.         } catch (IOException e) {  
  91.             e.printStackTrace();  
  92.         }  
  93.         return null;  
  94.     }  
  95.   
  96.     //3.高亮显示  实现了单条件查询  
  97.     //可改造为多条件查询  
  98.     public static List<IndexResult> highlight(IndexSearcher indexSearcher, String key) {  
  99.         try {  
  100.             QueryParser queryParser = new QueryParser("name"new StandardAnalyzer());  
  101.             Query query = queryParser.parse(key);  
  102.             TopDocCollector collector = new TopDocCollector(800);  
  103.             indexSearcher.search(query, collector);  
  104.             ScoreDoc[] hits = collector.topDocs().scoreDocs;  
  105.   
  106.             Highlighter highlighter = null;  
  107.             SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color='red'>",  
  108.                     "</font>");  
  109.             highlighter = new Highlighter(simpleHTMLFormatter, new QueryScorer(query));  
  110.             highlighter.setTextFragmenter(new SimpleFragmenter(200));  
  111.             List<IndexResult> list = new ArrayList<IndexResult>();  
  112.             Document doc;  
  113.             for (int i = 0; i < hits.length; i++) {  
  114.                 //System.out.println(hits[i].score);  
  115.                 doc = indexSearcher.doc(hits[i].doc);  
  116.                 TokenStream tokenStream = new StandardAnalyzer().tokenStream("name",  
  117.                         new StringReader(doc.get("name")));  
  118.                 IndexResult ir = getIndexResult(doc);  
  119.                 ir.setName(highlighter.getBestFragment(tokenStream, doc.get("name")));  
  120.                 list.add(ir);  
  121.             }  
  122.             return list;  
  123.         } catch (ParseException e) {  
  124.             e.printStackTrace();  
  125.         } catch (IOException e) {  
  126.             e.printStackTrace();  
  127.         }  
  128.         return null;  
  129.   
  130.     }  
  131.   
  132.     //4. 多字段查询  
  133.     @SuppressWarnings("deprecation")  
  134.     public static List<IndexResult> queryByMultiFileds(IndexSearcher indexSearcher,  
  135.             String[] fields, String key) {  
  136.         try {  
  137.             MultiFieldQueryParser mfq = new MultiFieldQueryParser(fields, new StandardAnalyzer());  
  138.             Query query = mfq.parse(key);  
  139.             Hits hits = indexSearcher.search(query);  
  140.             List<IndexResult> list = new ArrayList<IndexResult>();  
  141.             for (int i = 0; i < hits.length(); i++) {  
  142.                 list.add(getIndexResult(hits.doc(i)));  
  143.             }  
  144.   
  145.             return list;  
  146.         } catch (ParseException e) {  
  147.             e.printStackTrace();  
  148.         } catch (IOException e) {  
  149.             e.printStackTrace();  
  150.         }  
  151.         return null;  
  152.     }  
  153.   
  154.     //5. 删除索引  
  155.     public static void deleteIndex(String indexFile, String id) throws CorruptIndexException,  
  156.             IOException {  
  157.         IndexReader indexReader = IndexReader.open(indexFile);  
  158.         indexReader.deleteDocuments(new Term("id", id));  
  159.         indexReader.close();  
  160.     }  
  161.   
  162.     //6. 一元分词  
  163.     @SuppressWarnings("deprecation")  
  164.     public static String Standard_Analyzer(String str) {  
  165.         Analyzer analyzer = new StandardAnalyzer();  
  166.         Reader r = new StringReader(str);  
  167.         StopFilter sf = (StopFilter) analyzer.tokenStream("", r);  
  168.         System.out.println("=====StandardAnalyzer====");  
  169.         System.out.println("分析方法:默认没有词只有字(一元分词)");  
  170.         Token t;  
  171.         String results = "";  
  172.         try {  
  173.             while ((t = sf.next()) != null) {  
  174.                 System.out.println(t.termText());  
  175.                 results = results + " " + t.termText();  
  176.             }  
  177.         } catch (IOException e) {  
  178.             e.printStackTrace();  
  179.         }  
  180.         return results;  
  181.     }  
  182.   
  183.     //7. 字典分词  
  184.     @SuppressWarnings("deprecation")  
  185.     public static String ik_CAnalyzer(String str) {  
  186.         Analyzer analyzer = new IK_CAnalyzer();  
  187.         Reader r = new StringReader(str);  
  188.         TokenStream ts = (TokenStream) analyzer.tokenStream("", r);  
  189.         System.out.println("=====IK_CAnalyzer====");  
  190.         System.out.println("分析方法:字典分词,正反双向搜索");  
  191.         Token t;  
  192.         String results = "";  
  193.         try {  
  194.             while ((t = ts.next()) != null) {  
  195.                 System.out.println(t.termText());  
  196.                 results = results + " " + t.termText();  
  197.             }  
  198.         } catch (IOException e) {  
  199.             e.printStackTrace();  
  200.         }  
  201.         return results;  
  202.     }  
  203.   
  204.     //在结果中搜索  
  205.     public static void queryFromResults() {  
  206.   
  207.     }  
  208.   
  209.     //组装对象  
  210.     public static IndexResult getIndexResult(Document doc) {  
  211.         IndexResult ir = new IndexResult();  
  212.         ir.setId(doc.get("id"));  
  213.         ir.setName(doc.get("name"));  
  214.         ir.setAddress(doc.get("address"));  
  215.         ir.setCitycode(doc.get("citycode"));  
  216.         return ir;  
  217.     }  
  218. }  

 

    查询索引结果对象:IndexResult

Java代码  收藏代码
  1. package index;  
  2.   
  3. public class IndexResult {  
  4.   
  5.     private String id;  
  6.   
  7.     private String name;  
  8.   
  9.     private String address;  
  10.   
  11.     private String citycode;  
  12.   
  13.       
  14.     public String getId() {  
  15.         return id;  
  16.     }  
  17.     public void setId(String id) {  
  18.         this.id = id;  
  19.     }  
  20.     public String getName() {  
  21.         return name;  
  22.     }  
  23.     public void setName(String name) {  
  24.         this.name = name;  
  25.     }  
  26.   
  27.       
  28.     public String getAddress() {  
  29.         return address;  
  30.     }  
  31.     public void setAddress(String address) {  
  32.         this.address = address;  
  33.     }  
  34.     public String getCitycode() {  
  35.         return citycode;  
  36.     }  
  37.     public void setCitycode(String citycode) {  
  38.         this.citycode = citycode;  
  39.     }  
  40.       
  41. }  

 

4. 测试类

Java代码  收藏代码
  1. package test;  
  2.   
  3. /** 
  4.  * $Id$ 
  5.  * Copyright 2009-2010 Oak Pacific Interactive. All rights reserved. 
  6.  */  
  7.   
  8. import index.IndexResult;  
  9. import index.IndexUtils;  
  10.   
  11. import java.util.Date;  
  12. import java.util.List;  
  13.   
  14. import org.apache.lucene.search.IndexSearcher;  
  15.   
  16. public class Test {  
  17.   
  18.     //存放索引文件  
  19.     private static String indexFile = "E:\\workspace2\\Test\\lucene_test\\poiIdext";  
  20.   
  21.     //存放id  
  22.     private static String storeIdFile = "E:\\workspace2\\Test\\lucene_test\\storeId.txt";  
  23.   
  24.     public static void main(String[] args) throws Exception {  
  25.         //0. 创建增量索引  
  26.         IndexUtils.buildIndex(indexFile, storeIdFile);  
  27.           
  28.         IndexSearcher indexSearcher = new IndexSearcher(indexFile);  
  29.         String key = IndexUtils.ik_CAnalyzer("静安中心");  
  30.   
  31.         //1.单字段查询  
  32.         Date date1 = new Date();  
  33.         List<IndexResult> list = IndexUtils.queryByOneKey(indexSearcher, "name", key);  
  34.         Date date2 = new Date();  
  35.         System.out.println("耗时:" + (date2.getTime() - date1.getTime()) + "ms\n" + list.size()  
  36.                 + "条=======================================单字段查询");  
  37.         //printResults(list);  
  38.   
  39.         //2.多条件查询  
  40.         String[] fields = { "name""citycode" };  
  41.         String[] keys = { IndexUtils.ik_CAnalyzer("静安中心"), "0000" };  
  42.         date1 = new Date();  
  43.         list = IndexUtils.queryByMultiKeys(indexSearcher, fields, keys);  
  44.         date2 = new Date();  
  45.         System.out.println("耗时:" + (date2.getTime() - date1.getTime()) + "ms\n" + list.size()  
  46.                 + "条\n===============================多条件查询");  
  47.         printResults(list);  
  48.   
  49.         //3.高亮显示  单字段查询  
  50.         System.out.println("\n\n");  
  51.         date1 = new Date();  
  52.         list = IndexUtils.highlight(indexSearcher, key);  
  53.         date2 = new Date();  
  54.         System.out.println("耗时:" + (date2.getTime() - date1.getTime()) + "ms\n" + list.size()  
  55.                 + "条\n======================================高亮显示");  
  56.        // printResults(list);  
  57.   
  58.         //4. 多字段查询  
  59.         date1 = new Date();  
  60.         list = IndexUtils.queryByMultiFileds(indexSearcher, fields, key);  
  61.         date2 = new Date();  
  62.         System.out.println("耗时:" + (date2.getTime() - date1.getTime()) + "ms\n" + list.size()  
  63.                 + "条\n=====================================多字段查询");  
  64.        // printResults(list);  
  65.   
  66.         //5. 删除索引中的字段  根据id进行删除  
  67.         IndexUtils.deleteIndex(indexFile, "123");  
  68.     }  
  69.   
  70.     //打印结果  
  71.     public static void printResults(List<IndexResult> list) {  
  72.         if (list != null && list.size() > 0) {  
  73.             for (int i = 0; i < list.size(); i++) {  
  74.                 System.out.println(list.get(i).getId() + "," + list.get(i).getName() + ","  
  75.                         + list.get(i).getAddress() + "," + list.get(i).getCitycode()+"--->"+i);  
  76.             }  
  77.         }  
  78.     }  
  79. }  

 

5. 其它

 

全文索引:

目前的情况是,搜索hello,"hello world"、"hi hello, how are you"但"worldhello"显示不出来

 

默认情况下,QueryParser不支持通配符打头的查询(如,*ook)。不过在Lucene 2.1版本以后,他们可以通过调用QueryParser.setAllowLeadingWildcard( true )的 方法打开这一功能。注意,这是一个开销很大的操作:它需要扫描索引中全部记号的列表,来寻找匹配这个模式的词。(译注:高效支持这种后缀查询的办法是,建立反序的记号表,Lucene没有实现这一模式。)http://www.codechina.org/faq/show/42/

 

支持空格分词搜索:"厕所 26 沈阳" 这是三个词

不支持:“厕所沈阳”这是一个词

 

Lucene能实现“在搜索结果中搜索”的功能么,也就是说第二个搜索仅在第一个搜索结果中进行?

http://www.codechina.org/faq/show/63/

可以。主要有两种做法:

  • 使用QueryFilter把第一个查询当作一个过滤器处理。(你可以在Lucene的邮件列表里面搜索 QueryFilter,Doug Cutting(Lucene的最初作者)反对这种做法。
  • BooleanQuery把前后两个查询结合起来,前一个查询使用 required选项。

我们推荐使用BooleanQuery的方法。

 

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

 // 创建标准文本分析器, 标准的是可以支持的中文的

   Analyzer luceneAnalyzer = new StandardAnalyzer();

   indexWriter = new IndexWriter(indexDir, luceneAnalyzer, true);

   // 可以说是创建一个新的写入工具

   // 第一个参数是要索引建立在哪个目录里

   // 第二个参数是新建一个文本分析器,这里用的是标准的大家也可以自己写一个

   // 第三个参数如果是true,在建立索引之前先将c: \\index目录清空

 

 

 

poi_data_ugc搜索中,索引放在内存里还是磁盘上????


针对于lucene使用和优化

http://hi.baidu.com/lewutian/blog/item/48a86d03de58b984d43f7c1b.html

 

ucene入门实例(1):索引文本文件

http://www.java3z.com/cwbwebhome/article/article5/51021.html

0 0
原创粉丝点击