List of usage examples for org.apache.lucene.index IndexReader close
@Override public final synchronized void close() throws IOException
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.IndexInfoProxyService.java
License:Open Source License
/** * Chiude il mainReader associato ad un repository * * @param repoPath path dello store degli indici * @throws LuceneIndexException//from w ww . j a v a 2 s . co m * @throws IOException */ public synchronized void closeMainReader(String repoPath) throws LuceneIndexException, IOException { if (s_logger.isDebugEnabled()) { s_logger.debug("[IndexInfoProxyService::closeMainReader] (" + this + ") Status: " + toString() + " - isSafe: " + isIntegritySafe()); } // Creo un nuovo riferimento al main IndexReader main = getReader(repoPath); // Chiudo il primo invocato dalla chiamata getReader() main.close(); // Chiudo il secondo che era quello che dovevo effettivamente chiudere main.close(); }
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.IndexInfoProxyServiceNoTC.java
License:Open Source License
/** * Chiude il mainReader associato ad un repository * * @param repoPath path dello store degli indici * @throws LuceneIndexException/*ww w .j a v a 2s .co m*/ * @throws IOException */ public synchronized void closeMainReader(String repoPath) throws LuceneIndexException, IOException { if (s_logger.isDebugEnabled()) { s_logger.debug("[IndexInfoProxyServiceNoTC::closeMainReader] (" + this + ") Status: " + toString() + " - isSafe: " + isIntegritySafe()); } // Creo un nuovo riferimento al main IndexReader main = getReader(repoPath); // Chiudo il primo invocato dalla chiamata getReader() main.close(); // Chiudo il secondo che era quello che dovevo effettivamente chiudere main.close(); }
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerImpl.java
License:Open Source License
/** * Delete all index entries which do not start with the goven prefix * * @param prefix/* www .j a v a 2s. co m*/ */ public void deleteAll(String prefix) { IndexReader mainReader = null; try { // mainReader = getReader(); for (int doc = 0; doc < mainReader.maxDoc(); doc++) { if (!mainReader.isDeleted(doc)) { Document document = mainReader.document(doc); String[] ids = document.getValues("ID"); if ((prefix == null) || nonStartwWith(ids, prefix)) { deletions.add(ids[ids.length - 1]); } } } } catch (IOException e) { // If anything goes wrong we try and do a roll back throw new LuceneIndexException("Failed to delete all entries from the index", e); } finally { if (mainReader != null) { try { mainReader.close(); } catch (IOException e) { throw new LuceneIndexException("Filed to close main reader", e); } } } }
From source file:it.doqui.index.ecmengine.business.personalization.splitting.index.lucene.SplittingADMIndexerImpl.java
License:Open Source License
private void addRootNodesToDeletionList() { IndexReader mainReader = null; try {/*from w w w.j a v a2s . c o m*/ try { mainReader = getReader(); TermDocs td = mainReader.termDocs(new Term("ISROOT", "T")); while (td.next()) { int doc = td.doc(); Document document = mainReader.document(doc); String id = document.get("ID"); NodeRef ref = new NodeRef(id); deleteImpl(ref.toString(), false, true, mainReader); } } catch (IOException e) { throw new LuceneIndexException("Failed to delete all primary nodes", e); } } finally { if (mainReader != null) { try { mainReader.close(); } catch (IOException e) { throw new LuceneIndexException("Filed to close main reader", e); } } } }
From source file:it.doqui.index.ecmengine.business.personalization.splitting.index.lucene.SplittingADMIndexerImpl.java
License:Open Source License
void doFTSIndexCommit() throws LuceneIndexException { s_logger.error("###############################################################"); s_logger.error("###############################################################"); s_logger.error("###############################################################"); s_logger.error("### Root: '" + getLuceneConfig().getIndexRootLocation() + "'"); s_logger.error("###############################################################"); s_logger.error("###############################################################"); s_logger.error("###############################################################"); // TODO: controllare multirepo IndexReader mainReader = null; IndexReader deltaReader = null;/*from www . ja v a 2 s . c om*/ IndexSearcher mainSearcher = null; IndexSearcher deltaSearcher = null; try { try { mainReader = getReader(); deltaReader = getDeltaReader(); mainSearcher = new IndexSearcher(mainReader); deltaSearcher = new IndexSearcher(deltaReader); for (Helper helper : toFTSIndex) { deletions.add(helper.ref); } } finally { if (deltaSearcher != null) { try { deltaSearcher.close(); } catch (IOException e) { s_logger.warn("Failed to close delta searcher", e); } } if (mainSearcher != null) { try { mainSearcher.close(); } catch (IOException e) { s_logger.warn("Failed to close main searcher", e); } } try { closeDeltaReader(); } catch (LuceneIndexException e) { s_logger.warn("Failed to close delta reader", e); } if (mainReader != null) { try { mainReader.close(); } catch (IOException e) { s_logger.warn("Failed to close main reader", e); } } } setInfo(docs, getDeletions(), true); // mergeDeltaIntoMain(new LinkedHashSet<Term>()); } catch (IOException e) { // If anything goes wrong we try and do a roll back rollback(); throw new LuceneIndexException("Commit failed", e); } catch (LuceneIndexException e) { // If anything goes wrong we try and do a roll back rollback(); throw new LuceneIndexException("Commit failed", e); } finally { // Make sure we tidy up // deleteDelta(); } }
From source file:it.polito.tellmefirst.lucene.IndexesUtil.java
License:Open Source License
public static ArrayList<String> getBagOfConcepts(String uri, String lang) { LOG.debug("[getBagOfConcepts] - BEGIN"); ArrayList<String> result = new ArrayList<String>(); try {//from ww w.ja va 2s.co m String KBPath = (lang.equals("it")) ? TMFVariables.KB_IT : TMFVariables.KB_EN; MMapDirectory directory = new MMapDirectory(new File(KBPath)); IndexReader reader = IndexReader.open(directory, true); IndexSearcher is = new IndexSearcher(directory, true); Query q = new TermQuery(new Term("URI", uri)); TopDocs hits = is.search(q, 1); is.close(); if (hits.totalHits != 0) { int docId = hits.scoreDocs[0].doc; org.apache.lucene.document.Document doc = reader.document(docId); String wikilinksMerged = doc.getField("KB").stringValue(); String[] wikiSplits = wikilinksMerged.split(" "); //no prod LOG.debug("Bag of concepts for the resource " + uri + ": "); for (String s : wikiSplits) { result.add(s); //no prod LOG.debug("* " + s); } } reader.close(); } catch (Exception e) { LOG.error("[getBagOfConcepts] - EXCEPTION: ", e); } LOG.debug("[getBagOfConcepts] - END"); return result; }
From source file:it.polito.tellmefirst.lucene.IndexesUtil.java
License:Open Source License
public static ArrayList<String> getResidualBagOfConcepts(String uri, String lang) { LOG.debug("[getResidualBagOfConcepts] - BEGIN"); ArrayList<String> result = new ArrayList<String>(); try {//from w w w. j a va 2 s . c om String residualKBPath = (lang.equals("it")) ? TMFVariables.RESIDUAL_KB_IT : TMFVariables.RESIDUAL_KB_EN; MMapDirectory directory = new MMapDirectory(new File(residualKBPath)); IndexReader reader = IndexReader.open(directory, true); IndexSearcher is = new IndexSearcher(directory, true); Query q = new TermQuery(new Term("URI", uri)); TopDocs hits = is.search(q, 1); is.close(); if (hits.totalHits != 0) { int docId = hits.scoreDocs[0].doc; org.apache.lucene.document.Document doc = reader.document(docId); String wikilinksMerged = doc.getField("KB").stringValue(); String[] wikiSplits = wikilinksMerged.split(" "); //no prod LOG.debug("Residual bag of concepts for the resource " + uri + ": "); for (String s : wikiSplits) { result.add(s); //no prod LOG.debug("* " + s); } } reader.close(); } catch (Exception e) { LOG.error("[getResidualBagOfConcepts] - EXCEPTION: ", e); } LOG.debug("[getResidualBagOfConcepts] - END"); return result; }
From source file:it.polito.tellmefirst.lucene.KBIndexSearcher.java
License:Open Source License
/** * Get DBpedia concepts related to a specific URI from the Lucene Index. These DBpedia concepts appear as wikilink * more than once in the Wikipedia page identified by the URI. * * @param uri Input URI.//from www .java 2s . c o m * * In the previous versions of TellMeFirst, the getBagOfConcepts method take as input the * URI of a DBpedia resource (String) and the language parameter (String). We have decide to * modify the API in order to separate this module from the core of TellMeFirst. * * @since 3.0.0.0. */ public List<String> getBagOfConcepts(String uri) throws Exception { LOG.debug("[getBagOfConcepts] BEGIN"); List<String> result = new ArrayList<String>(); try { MMapDirectory directory = new MMapDirectory(new File(kb)); IndexReader reader = IndexReader.open(directory, true); IndexSearcher is = new IndexSearcher(directory, true); Query q = new TermQuery(new Term("URI", uri)); TopDocs hits = is.search(q, 1); is.close(); if (hits.totalHits != 0) { int docId = hits.scoreDocs[0].doc; org.apache.lucene.document.Document doc = reader.document(docId); String wikilinksMerged = doc.getField("KB").stringValue(); String[] wikiSplits = wikilinksMerged.split(" "); LOG.debug("Bag of concepts for the resource " + uri + ": "); for (String s : wikiSplits) { result.add(s); LOG.debug("* " + s); } } reader.close(); } catch (Exception e) { LOG.error("[getBagOfConcepts] EXCEPTION: ", e); throw new Exception(e); } LOG.debug("[getBagOfConcepts] END"); return result; }
From source file:it.polito.tellmefirst.lucene.KBIndexSearcher.java
License:Open Source License
/** * Get DBpedia concepts related to a specific URI from the Lucene Index. These DBpedia concepts appear as wikilink * once in the Wikipedia page identified by the URI. * * @param uri Input URI.//w ww .j a v a 2 s . c o m * * In the previous versions of TellMeFirst, the getResidualBagOfConcepts method take as input the * URI of a DBpedia resource (String) and the language parameter (String). We have decide to * modify the API in order to separate this module from the core of TellMeFirst. * * @since 3.0.0.0. */ public ArrayList<String> getResidualBagOfConcepts(String uri) { LOG.debug("[getResidualBagOfConcepts] - BEGIN"); ArrayList<String> result = new ArrayList<String>(); try { MMapDirectory directory = new MMapDirectory(new File(residualKb)); IndexReader reader = IndexReader.open(directory, true); IndexSearcher is = new IndexSearcher(directory, true); Query q = new TermQuery(new Term("URI", uri)); TopDocs hits = is.search(q, 1); is.close(); if (hits.totalHits != 0) { int docId = hits.scoreDocs[0].doc; org.apache.lucene.document.Document doc = reader.document(docId); String wikilinksMerged = doc.getField("KB").stringValue(); String[] wikiSplits = wikilinksMerged.split(" "); //no prod LOG.debug("Residual bag of concepts for the resource " + uri + ": "); for (String s : wikiSplits) { result.add(s); //no prod LOG.debug("* " + s); } } reader.close(); } catch (Exception e) { LOG.error("[getResidualBagOfConcepts] - EXCEPTION: ", e); } LOG.debug("[getResidualBagOfConcepts] - END"); return result; }
From source file:it.unibz.instasearch.indexing.SearchResultDoc.java
License:Open Source License
/** * /*from ww w .j av a 2s . c om*/ * @return * @throws IOException */ private float[] getTermScoreVector() throws IOException { if (termScoreVector == null) { IndexReader reader = IndexReader.open(indexDir, true); if (termFreqVector == null) createFreqVect(reader); termScoreVector = createTermScoreVector(termFreqVector, reader); reader.close(); } return termScoreVector; }