List of usage examples for org.apache.lucene.index IndexWriterConfig setOpenMode
public IndexWriterConfig setOpenMode(OpenMode openMode)
From source file:net.semanticmetadata.lire.indexing.tools.Indexor.java
License:Open Source License
public void run() { // do it ...//from ww w .j a v a2s. c om try { // IndexWriter indexWriter = LuceneUtils.createIndexWriter(indexPath, overwriteIndex, LuceneUtils.AnalyzerType.WhitespaceAnalyzer); IndexWriterConfig config = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION)); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); config.setCodec(new LireCustomCodec()); IndexWriter indexWriter = new IndexWriter(FSDirectory.open(new File(indexPath)), config); for (Iterator<File> iterator = inputFiles.iterator(); iterator.hasNext();) { File inputFile = iterator.next(); if (verbose) System.out.println("Processing " + inputFile.getPath() + "."); readFile(indexWriter, inputFile); if (verbose) System.out.println("Indexing finished."); } indexWriter.commit(); indexWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.semanticmetadata.lire.utils.LuceneUtils.java
License:Open Source License
/** * Creates an IndexWriter for given index path, with given analyzer. * * @param directory the path to the index directory * @param create set to true if you want to create a new index * @param analyzer gives the analyzer used for the Indexwriter. * @return an IndexWriter// ww w .j a v a 2 s .co m * @throws IOException */ public static IndexWriter createIndexWriter(Directory directory, boolean create, AnalyzerType analyzer) throws IOException { // set the analyzer according to the method params Analyzer tmpAnalyzer = null; if (analyzer == AnalyzerType.SimpleAnalyzer) tmpAnalyzer = new SimpleAnalyzer(); // LetterTokenizer with LowerCaseFilter else if (analyzer == AnalyzerType.WhitespaceAnalyzer) tmpAnalyzer = new WhitespaceAnalyzer(); // WhitespaceTokenizer else if (analyzer == AnalyzerType.KeywordAnalyzer) tmpAnalyzer = new KeywordAnalyzer(); // entire string as one token. else if (analyzer == AnalyzerType.StandardAnalyzer) tmpAnalyzer = new StandardAnalyzer(); // The config IndexWriterConfig config = new IndexWriterConfig(tmpAnalyzer); config.setRAMBufferSizeMB(512); config.setCommitOnClose(true); if (create) config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // overwrite if it exists. else config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); // create new if none is there, append otherwise. config.setCodec(new LireCustomCodec()); return new IndexWriter(directory, config); }
From source file:net.semanticmetadata.lire.utils.LuceneUtils.java
License:Open Source License
public static IndexWriter createIndexWriter(Directory directory, boolean create, AnalyzerType analyzer, double RAMBufferSize) throws IOException { // set the analyzer according to the method params Analyzer tmpAnalyzer = null;//from ww w. j a v a 2 s .c o m if (analyzer == AnalyzerType.SimpleAnalyzer) tmpAnalyzer = new SimpleAnalyzer(); else if (analyzer == AnalyzerType.WhitespaceAnalyzer) tmpAnalyzer = new WhitespaceAnalyzer(); // The config IndexWriterConfig config = new IndexWriterConfig(tmpAnalyzer); if (create) config.setOpenMode(IndexWriterConfig.OpenMode.CREATE); // overwrite if it exists. else config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); // create new if none is there, append otherwise. config.setRAMBufferSizeMB(RAMBufferSize); config.setCodec(new LireCustomCodec()); return new IndexWriter(directory, config); }
From source file:net.sf.lucis.core.impl.DefaultWriter.java
License:Apache License
public <T, P> IndexStatus write(Store<T> store, Batch<T, P> batch) throws InterruptedException { Preconditions.checkNotNull(store, "A destination store must be provided."); if (batch == null) { return null; }/* w ww. j a v a 2s . c om*/ try { final IndexWriterConfig config = config(); final T oldCP = store.getCheckpoint(); final T newCP = batch.getCheckpoint(); if (Objects.equal(oldCP, newCP)) { return null; } throwIfInterrupted(); if (!batch.isEmpty()) { final Analyzer analyzer = config.getAnalyzer(); // Check whether the index must be created final Directory directory = store.getDirectory(); config.setOpenMode(batch.isRecreate() ? OpenMode.CREATE : OpenMode.CREATE_OR_APPEND); final IndexWriter writer = new IndexWriter(directory, config); boolean ok = false; try { // Deletions if (!batch.isRecreate()) { for (Term term : batch.getDeletions()) { throwIfInterrupted(); writer.deleteDocuments(term); } } // Additions for (Addition addition : batch.getAdditions()) { throwIfInterrupted(); final Analyzer aa = addition.getAnalyzer(); writer.addDocument(addition.getDocument(), aa != null ? aa : analyzer); } // Commit throwIfInterrupted(); writer.commit(); ok = true; // No optimize until policy is defined. // writer.optimize(); } finally { if (!ok) { rollback(writer); } writer.close(); } } store.setCheckpoint(newCP); return IndexStatus.OK; } catch (InterruptedException ie) { throw ie; } catch (LockObtainFailedException le) { log().error(le, "Unable to lock index"); return IndexStatus.LOCKED; } catch (CorruptIndexException ce) { log().error(ce, "Corrupt index"); return IndexStatus.CORRUPT; } catch (IOException ioe) { log().error(ioe, "I/O Error while writing"); return IndexStatus.IOERROR; } catch (Exception e) { log().error(e, "Exception while writing"); return IndexStatus.ERROR; } }
From source file:net.sf.okapi.lib.tmdb.lucene.Writer.java
License:Open Source License
/** * Creates a OWriter object/*from w w w . j a va 2 s . com*/ * * @param indexDirectory * - the Lucene Directory implementation of choice. * @param createNewTmIndex * Set to false to append to the existing TM index file. Set to true to overwrite. * @throws IOException * if the indexDirectory can not load */ public Writer(Directory indexDirectory, boolean createNewTmIndex) throws IOException { IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_31, new NgramAnalyzer(Locale.ENGLISH, 4)); iwc.setOpenMode(createNewTmIndex ? OpenMode.CREATE : OpenMode.CREATE_OR_APPEND); indexWriter = new IndexWriter(indexDirectory, iwc); }
From source file:net.simpleframework.ado.lucene.AbstractLuceneManager.java
License:Apache License
protected IndexWriter createIndexWriter() throws IOException { final IndexWriterConfig iwConfig = new IndexWriterConfig(getDefaultAnalyzer()); iwConfig.setOpenMode(OpenMode.CREATE_OR_APPEND); return new IndexWriter(directory, iwConfig); }
From source file:net.skyatlas.icd.test.RAMDirectoryDemo.java
public static void main(String[] args) throws IOException { long startTime = System.currentTimeMillis(); System.err.println("*************************** ****************************"); RAMDirectory directory = new RAMDirectory(); Version matchVersion = Version.LUCENE_48; Analyzer analyzer = new StandardAnalyzer(matchVersion); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_48, analyzer); iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, iwc); Document doc = new Document(); doc.add(new Field("name", "Chenghui", Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field("sex", "", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("dosometing", "I am learning lucene ", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc);//w w w .jav a2s. co m writer.close(); IndexReader reader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(reader); Query query = new TermQuery(new Term("dosometing", "lucene")); TopDocs rs = searcher.search(query, null, 10); long endTime = System.currentTimeMillis(); System.out.println( "" + (endTime - startTime) + "" + rs.totalHits + "?"); for (int i = 0; i < rs.scoreDocs.length; i++) { // rs.scoreDocs[i].doc ??id, 0 Document firstHit = searcher.doc(rs.scoreDocs[i].doc); System.out.println("name:" + firstHit.getField("name").stringValue()); System.out.println("sex:" + firstHit.getField("sex").stringValue()); System.out.println("dosomething:" + firstHit.getField("dosometing").stringValue()); } reader.close(); directory.close(); System.out.println("*****************?**********************"); }
From source file:net.skyatlas.icd.util.MemoryGrid.java
public void init() throws IOException, CorruptIndexException, InvalidTokenOffsetsException, ParseException, SQLException { System.err.println("--------------\t\t Memory Grid Initializing -------------"); this.allDiseases = this.dao.getAllDisease(); // Vol1 ? this.allIndexItems = this.dao.getAllDiseaseIndexes(); // Vol3 ? this.allIndexRelations = this.dao.getAllIcdDiseaseIdxRelations(); //Vol3 ? this.allDisRelations = this.icdDisRelationDao.getAllDiseaseRelation();//Vol1 ? // ?/* w ww . j a v a 2 s. com*/ if (this.allRootIndexItems == null) { this.allRootIndexItems = new ArrayList(); } System.err.println("All Index Items size:" + allIndexItems.size()); System.err.println("All Disease Items size:" + allDiseases.size()); //Vol1 Relation for (int i = 0; i < this.allDisRelations.size(); i++) { IcdDiseaseRelation r = this.allDisRelations.get(i); this.getVol1IDRelationIndexedItems().put(r.getId(), r); List<IcdDiseaseRelation> list = this.getVol1mainIDRelationIndexedItems().get(r.getMainID()); if (list == null || list.size() == 0) { list = new ArrayList(); list.add(r); this.getVol1mainIDRelationIndexedItems().put(r.getMainID(), list); } else { list.add(r); } } // Vol 1 for (int i = 0; i < this.allDiseases.size(); i++) { IcdDisease d = this.allDiseases.get(i); //set Relations List<IcdDiseaseRelation> icdDisRelations = new ArrayList(); icdDisRelations = this.getVol1mainIDRelationIndexedItems().get(d.getId()); HashMap<String, List<IcdDiseaseRelation>> refRelations = new HashMap(); List<IcdDiseaseRelation> noIncludeList = new ArrayList();//d.getRefRelations().get("?"); List<IcdDiseaseRelation> otherCodeList = new ArrayList();//d.getRefRelations().get("??"); List<IcdDiseaseRelation> swordList = new ArrayList();//d.getRefRelations().get(""); List<IcdDiseaseRelation> includeList = new ArrayList();//d.getRefRelations().get(""); if (icdDisRelations == null || icdDisRelations.size() == 0) { } else { for (int j = 0; j < icdDisRelations.size(); j++) { IcdDiseaseRelation idr = icdDisRelations.get(j); if (idr.getRelationType().equals("?")) { noIncludeList.add(idr); } else if (idr.getRelationType().equals("??")) { otherCodeList.add(idr); } else if (idr.getRelationType().equals("")) { swordList.add(idr); } else if (idr.getRelationType().equals("")) { includeList.add(idr); } } if (noIncludeList.size() > 0) { refRelations.put("?", noIncludeList); } if (otherCodeList.size() > 0) { refRelations.put("??", otherCodeList); } if (swordList.size() > 0) { refRelations.put("", swordList); } if (includeList.size() > 0) { refRelations.put("", includeList); } } d.setRefRelations(refRelations); // ID Unique Index this.getVol1IDIndexedItems().put(d.getId(), d); // System.err.println(" ? IcdDisease, ICD Code :"+d.getIcdCode()); // ICD Code if (d.getIcdCode() != null && d.getIcdCode().length() > 0) { // ICD ?? List<IcdDisease> alIndexes; if (this.getVol1IcdIndexedItems().containsKey(d.getIcdCode().toUpperCase())) { alIndexes = this.getVol1IcdIndexedItems().get(d.getIcdCode().toUpperCase()); } else { alIndexes = new ArrayList(); } // System.err.println("Index Disease :"+d.getIcdCode()); alIndexes.add(d); this.getVol1IcdIndexedItems().put(d.getIcdCode().replaceAll("$", "").toUpperCase(), alIndexes); } // Vol1 Name List<IcdDisease> alIndexes2; if (this.getVol1NameIndexedItems().containsKey(d.getCodeNameCh())) { alIndexes2 = this.getVol1NameIndexedItems().get(d.getCodeNameCh()); } else { alIndexes2 = new ArrayList(); } alIndexes2.add(d); this.getVol1NameIndexedItems().put(d.getCodeNameCh(), alIndexes2); // Vol1 List<IcdDisease> alIndexes3; if (this.getVol1PinYinIndexedItems().containsKey(d.getPy())) { alIndexes3 = this.getVol1PinYinIndexedItems().get(d.getPy()); } else { alIndexes3 = new ArrayList(); } alIndexes3.add(d); this.getVol1PinYinIndexedItems().put(d.getPy(), alIndexes3); } /* Vol1parent-children */ for (int i = 0; i < this.allDiseases.size(); i++) { IcdDisease d = this.allDiseases.get(i); if (d.getParentID() != null && d.getParentID() != 0) { IcdDisease parent = this.getVol1IDIndexedItems().get(d.getParentID()); d.setParentDisease(parent); if (parent == null) { System.err.println(" parent is null :" + d.getId() + "\t" + d.getParentID()); continue; } if (parent.getChildren() == null) { parent.setChildren(new ArrayList()); } parent.getChildren().add(d); } } // Vol 3 for (int i = 0; i < this.allIndexItems.size(); i++) { IcdDiseaseIndex e = this.allIndexItems.get(i); this.getVol3IDIndexedItems().put(e.getId(), e); // ID Unique // ?? List<IcdDiseaseIndex> alIdxes; if (this.getVol3NameIndexedItems().containsKey(e.getNameCh())) { alIdxes = this.getVol3NameIndexedItems().get(e.getNameCh()); } else { alIdxes = new ArrayList(); } alIdxes.add(e); this.getVol3NameIndexedItems().put(e.getNameCh(), alIdxes); // List<IcdDiseaseIndex> alIdxes2; if (this.getVol3PinYinIndexedItems().containsKey(e.getPy())) { alIdxes2 = this.getVol3PinYinIndexedItems().get(e.getPy()); } else { alIdxes2 = new ArrayList(); } alIdxes2.add(e); this.getVol3PinYinIndexedItems().put(e.getPy(), alIdxes2); // ????? if (this.dealAlias) { List<String> slist = new ArrayList(); slist = dao.getAliasesByIndexid(e.getId()); if (slist.size() != 0) { String[] aliases = new String[slist.size()]; slist.toArray(aliases); e.setAliases(aliases); } } if (e.getDepth() == 0) { // Vol3 Item ? this.allRootIndexItems.add(e); // Pattern p = Pattern.compile("[\\[]"); // Matcher m = p.matcher(e.getNameCh()); // while (m.find()) { // System.err.println("[]??:\t"+e.getNameCh()+"-> startIndex:"+m.start()+"-> endIndex:"+m.end()+" Match:"+m.group()); // } // Pattern p2 = Pattern.compile("[]\\)"); // Matcher m2 = p2.matcher(e.getNameCh()); // while (m2.find()) { // System.err.println("(?)??:\t"+e.getNameCh()+"-> startIndex:"+m2.start()+"-> endIndex:"+m2.end()+" Match:"+m2.group()); // } // p2 = Pattern.compile(pstr1); // m2 = p2.matcher(e.getNameCh()); // while (m2.find()) { // System.err.println(" () [] "+m2.group()+"-->"+e.getNameCh()+"->"+m2.group(1)); // } // // p2 = Pattern.compile(pstr2); // m2 = p2.matcher(e.getNameCh()); // while (m2.find()) { // System.err.println(" [] () "+m2.group()+"-->"+e.getNameCh()); // } // // // p2 = Pattern.compile(pstr3); // m2 = p2.matcher(e.getNameCh()); // while (m2.find()) { // System.err.println(" [] ? "+m2.group()+"-->"+e.getNameCh()); // } // // // p2 = Pattern.compile(pstr4); // m2 = p2.matcher(e.getNameCh()); // while (m2.find()) { // System.err.println(" () ? "+m2.group()+"-->"+e.getNameCh()); // } // ?? /* parseRootIndex(e); e.getParseTreeRoot().setDepth(0); System.out.println("? " + e.getNameCh() + " \n Parse Result :" + e.getParseTreeRoot().toString()); */ } // ??? } //Vol3 parent-children for (int i = 0; i < this.allIndexItems.size(); i++) { IcdDiseaseIndex idi = this.allIndexItems.get(i); if (idi.getParentID() != null && idi.getParentID() != 0) { IcdDiseaseIndex parent = this.getVol3IDIndexedItems().get(idi.getParentID()); idi.setParentDiseaseIndex(parent); if (parent == null) { System.err.println(" parent is null :" + idi.getId() + "\t" + idi.getParentID()); continue; } if (parent.getChildren() == null) { parent.setChildren(new ArrayList()); } parent.getChildren().add(idi); } } // ? Vol3 for (IcdDiseaseIndex idi : this.allIndexItems) { // ICD ?? if (idi.getIcdCode() != null && idi.getIcdCode().length() > 0) { Stack<IcdDiseaseIndex> v = new Stack(); createIdexSearchPath(v, idi); // ? SearchPath path = new SearchPath(); Iterator<IcdDiseaseIndex> itr = v.iterator(); while (itr.hasNext()) { IcdDiseaseIndex i = itr.next(); path.getNodeList().add(i); // IcdDiseaseIndex Parse if (idi.getDepth() > 0) { /* parseRootIndex(idi); */ } } path.setNodes(path.getNodeList().size()); path.setStartPoint(path.getNodeList().get(0)); // Get Terminal ICD Disease /* M72.5 Vol1 ? D54 Vol1 ? W13 Vol1 */ List<IcdDisease> ds = this.getVol1IcdIndexedItems() .get(idi.getIcdCode().replaceAll("$", "").toUpperCase()); if (ds == null) { // Maybe the icd code in Vol3 cannot be found in Vol1, Skip this item... ds = this.getVol1IcdIndexedItems().get(idi.getIcdCode().replaceAll("$", "") .replaceAll("\\.$", "").replace(".-", "").toUpperCase()); if (ds == null) { System.err.println("ICD CODE:" + idi.getIcdCode() + " Indexed ?" + this.getVol1IcdIndexedItems().containsKey(idi.getIcdCode().toUpperCase()) + "--" + idi.getIcdCode().replaceAll("$", "").replaceAll("\\.$", "") .replace(".-", "").toUpperCase()); continue; } } for (IcdDisease dis : ds) { if (dis.getCodeType().equals("") || dis.getCodeType().equals("")) { continue; } path.setTerminal(dis); } // ??? setDimension(path, path.getTerminal()); // this.getAllSearchPaths().add(path); this.getGuidIndexedSearchPaths().put(path.getPathHashCode(), path); // ??ICD Code List<SearchPath> al1 = this.getIcdIndexedSearchPaths() .get(path.getTerminal().getIcdCode().toUpperCase()); if (al1 == null) { al1 = new ArrayList<SearchPath>(); } al1.add(path); this.getIcdIndexedSearchPaths().put(path.getTerminal().getIcdCode().toUpperCase(), al1); // ??(ICDDiseaseIndex) List<SearchPath> al2 = this.getRootIndexedSearchPaths().get(path.getStartPoint()); // SearchPath al2 = this.getRootIndexedSearchPaths().get(path.getStartPoint()); if (al2 == null || al2.size() == 0) { //al2 = new SearchPath(); al2 = new ArrayList(); } al2.add(path); this.getRootIndexedSearchPaths().put(path.getStartPoint(), al2); } } /*2014-06-11 15:28:22 * Vol1parent-children for(int i =0;i<this.allIndexItems.size();i++){ IcdDiseaseIndex d = this.allIndexItems.get(i); if(d.getParentID()!=null&&d.getParentID()!=0){ IcdDiseaseIndex parent = this.getVol3IDIndexedItems().get(d.getParentID()); d.setParentDiseaseIndex(parent); if(parent == null){ System.err.println(" parent is null :"+d.getId()+"\t"+d.getParentID()); continue; } if(parent.getChildren() ==null){ parent.setChildren(new ArrayList()); } parent.getChildren().add(d); } } */ // ? End! /* ?: 1. ICDDisease ? children --> ? 2. ICDDisease ?Lucene --> ? 3. search ? */ System.err.println("Search Path #:" + this.getAllSearchPaths().size()); System.err.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); // for (SearchPath sp : this.getAllSearchPaths()) { // System.err.println(sp); // } System.err.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); /* for (IcdDiseaseIndex idi : this.allRootIndexItems) { System.err.println("? :" + idi.getNameCh() + "->" + idi.getPage() + "-" + idi.getPathStr() + "-" + idi.getDepth()); List<SearchPath> paths = this.getRootIndexedSearchPaths().get(idi); if (paths == null) { System.err.println("\t Search Path"); } else { for (SearchPath sp : paths) { System.err.println("\t "+sp.getIndexString()); } } } */ System.err.println("******************* Begin create Idnex *********************"); HashSet<String> hs = new HashSet<String>(); BufferedReader reader2 = IOUtil.getReader(ResourceBundle.getBundle("library").getString("stopLibrary"), "UTF-8"); String word = null; while ((word = reader2.readLine()) != null) { hs.add(word); } // MemoryGrid Lucene ?? directory = new RAMDirectory(); Version matchVersion = Version.LUCENE_48; analyzer = new AnsjAnalysis(hs, false); /* TokenStream ts = analyzer.tokenStream("", "?"); // CharTermAttribute term = ts.addAttribute(CharTermAttribute.class); System.err.println(" Test ?"); while (ts.incrementToken()) { System.out.println("?" + ts.getAttribute(CharTermAttribute.class) + ""); } ts.close(); */ IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_48, analyzer); iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, iwc); // ? for (SearchPath path : this.getAllSearchPaths()) { // System.err.println(" ? :"+path.getIndexString()); addContent(writer, path.getIndexString(), path.getPathHashCode(), path.getNodes(), "vol3"); } writer.commit(); writer.close(); System.err.println("***************** index created *******************"); System.out.println(""); // search(analyzer,directory,"?"); //DEBUG: HIS?? ?ICD?? /* try { OracleDataSource ods = new OracleDataSource(); ods.setURL("jdbc:oracle:thin:@//192.168.1.115:1521/omac"); ods.setUser("oracle"); ods.setPassword("quickhis"); Connection conn = ods.getConnection(); String sql = "select main_icd,diag_name from fir_out_diag_tab where diag_date > (sysdate-1000) and rownum < 1000"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { String mainIcd = rs.getString(1); String diagName = rs.getString(2); if (diagName==null || "".equals(diagName)) { continue; } diagName = diagName.replaceAll("", "(").replaceAll("", ")"); System.err.println(" ICD_CODE:"+mainIcd+"\t >>"+diagName); search(analyzer,directory,diagName); } rs.close(); stmt.close(); conn.close(); } catch (SQLException ex) { ex.printStackTrace(); } */ }
From source file:net.techest.railgun.index.Index.java
License:Apache License
/** * * @param indexdir// w w w. j a v a 2 s . c o m * @param readMode * @throws IOException */ public Index(String indexdir, boolean readMode) throws IOException { fsDir = new SimpleFSDirectory(new File(indexdir)); // ???? if (readMode) { fsIs = new IndexSearcher(fsDir, true); return; } ramDir = new RAMDirectory(); if (Configure.getSystemConfig().getString("LOADTOMEM", "false").toLowerCase().equals("true")) { ramDir = new RAMDirectory(fsDir); } IKAnalyzer ika = new IKAnalyzer(); IndexWriterConfig fsIwc = new IndexWriterConfig(Version.LUCENE_34, ika); fsIwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); fsIwc.setWriteLockTimeout(-1); fsIwc.setRAMBufferSizeMB(Configure.getSystemConfig().getInt("INDEX_FS_BUFFER", 16)); IndexWriterConfig ramIwc = new IndexWriterConfig(Version.LUCENE_34, ika); ramIwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); ramIwc.setWriteLockTimeout(-1); ramIwc.setRAMBufferSizeMB(Configure.getSystemConfig().getInt("INDEX_RAM_BUFFER", 128)); ramWriter = new IndexWriter(ramDir, ramIwc); fsWriter = new IndexWriter(fsDir, fsIwc); fsIs = null; ramIs = null; try { fsIs = new IndexSearcher(fsDir, true); } catch (IOException ex) { } try { ramIs = new IndexSearcher(ramDir, true); } catch (IOException ex) { } }
From source file:net.techest.railgun.test.TestIndex.java
License:Apache License
public static void main(String[] args) throws IOException { SimpleFSDirectory ramDir = new SimpleFSDirectory(new File("index")); IKAnalyzer ika = new IKAnalyzer(); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_34, ika); iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(ramDir, iwc); Document doc = new Document(); Field f = new Field("source", "lucene???Lucene????PDF????????", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES); doc.add(f);/*from ww w.j av a 2 s .c o m*/ writer.addDocument(doc); writer.close(); }