List of usage examples for org.apache.lucene.index IndexReader close
@Override public final synchronized void close() throws IOException
From source file:lius.lucene.LuceneActions.java
License:Apache License
public synchronized void deleteAllDocuments(String indexDir) { try {/*from www.ja v a 2 s. co m*/ Directory directory = FSDirectory.getDirectory(indexDir, false); IndexReader ir = IndexReader.open(directory); int num = ir.numDocs(); for (int i = 0; i <= num - 1; i++) { ir.deleteDocument(i); } if (ir != null) { ir.close(); } } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:lius.lucene.LuceneActions.java
License:Apache License
public synchronized List ListAllDocuments(String indexDir, LiusConfig lc) { List documentsList = new ArrayList(); List fieldList = lc.getBrowseFieldsToDisplay(); Map values = null;//from www . ja v a 2 s. c o m LiusHit lh = null; try { Directory directory = FSDirectory.getDirectory(indexDir, false); IndexReader ir = IndexReader.open(directory); int num = ir.numDocs(); for (int i = 0; i <= num - 1; i++) { lh = new LiusHit(); values = new HashMap(); Document luceneDoc = ir.document(i); lh.setDocId(i); for (int j = 0; j < fieldList.size(); j++) { LiusField lf = (LiusField) fieldList.get(j); Field f = luceneDoc.getField(lf.getName()); LiusField nlf = new LiusField(); nlf.setName(lf.getName()); nlf.setLabel(lf.getLabel()); if (f != null) { String content = f.stringValue(); nlf.setValue(content); values.put(lf.getName(), nlf); } } lh.setLiusFieldsMap(values); documentsList.add(lh); } if (ir != null) { ir.close(); } } catch (IOException e) { logger.error(e.getMessage()); } return documentsList; }
From source file:lius.lucene.LuceneActions.java
License:Apache License
public synchronized void unDeleteAllDocuments(String indexDir) { try {/*w ww . j ava2 s .c o m*/ Directory directory = FSDirectory.getDirectory(indexDir, false); IndexReader ir = IndexReader.open(directory); ir.undeleteAll(); if (ir != null) { ir.close(); } } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:lius.lucene.LuceneActions.java
License:Apache License
/** * Mthode permettant d'effacer un document dans l'index. Elle prend comme * arguments le rpertoire de l'index, le nom du champs et le contenu * recherch. <br/><br/>Method that erases a document from the index. Its * parameters are the directory of the index, the name of the field and the * content searched.//from w w w . j a v a 2 s. co m */ public synchronized int deleteDoc(String indexDir, String field, String content) throws LiusException { int nbDelete = 0; try { Directory fsDir = FSDirectory.getDirectory(indexDir, false); IndexReader indexReader = IndexReader.open(fsDir); Term t = new Term(field, content); nbDelete = indexReader.deleteDocuments(t); if (indexReader != null) { indexReader.close(); } logger.debug("Document supprim"); } catch (IOException e) { logger.error(e.getMessage()); } return nbDelete; }
From source file:lius.lucene.LuceneActions.java
License:Apache License
/** * Mthode permettant d'effacer un document dans l'index. Elle prend comme * arguments le rpertoire de l'index et un objet de type Lucene Term. <br/> * <br/>Method that erases a document from the index. Its parameters are the * directory of the index and a Lucene term object. *//*from w ww. j a v a 2 s .c o m*/ public synchronized int deleteDoc(String indexDir, Term t) throws LiusException { int nbDelete = 0; try { Directory fsDir = FSDirectory.getDirectory(indexDir, false); IndexReader indexReader = IndexReader.open(fsDir); nbDelete = indexReader.deleteDocuments(t); if (indexReader != null) { indexReader.close(); } logger.info("Document supprim"); } catch (IOException e) { logger.error(e.getMessage()); } return nbDelete; }
From source file:lius.lucene.LuceneActions.java
License:Apache License
public synchronized void deleteDoc(String indexDir, int docNum) throws LiusException { try {//from w w w .j ava2 s . c om Directory fsDir = FSDirectory.getDirectory(indexDir, false); IndexReader indexReader = IndexReader.open(fsDir); indexReader.deleteDocument(docNum); if (indexReader != null) { indexReader.close(); } logger.info("Document supprim"); } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:lsre.utils.LuceneUtils.java
License:Open Source License
public static void closeReader(IndexReader reader) throws IOException { reader.close(); }
From source file:lucee.runtime.search.lucene2.LuceneSearchCollection.java
License:Open Source License
private static void close(IndexReader reader) throws SearchException { if (reader != null) { try {/*from w w w. ja va2 s.c o m*/ reader.close(); } catch (IOException e) { throw new SearchException(e); } } }
From source file:lucee.runtime.search.lucene2.LuceneSearchCollection.java
License:Open Source License
private static void closeEL(IndexReader reader) { //print.out("r-closeEL"); if (reader != null) { try {//from w w w . j a v a 2s .c om reader.close(); } catch (Throwable t) { //throw new SearchException(t); } } }
From source file:lucene.CosineDocumentSimilarity.java
CosineDocumentSimilarity(String s1, String s2) throws IOException { Directory directory = createIndex(s1, s2); IndexReader reader = DirectoryReader.open(directory); Map<String, Integer> f1 = getTermFrequencies(reader, 0); Map<String, Integer> f2 = getTermFrequencies(reader, 1); reader.close(); v1 = toRealVector(f1);/*from w w w . ja v a2 s .c o m*/ v2 = toRealVector(f2); }