List of usage examples for org.apache.lucene.store FSDirectory open
public static FSDirectory open(Path path, LockFactory lockFactory) throws IOException
From source file:arena.lucene.LuceneDirectoryBean.java
License:Open Source License
public void afterPropertiesSet() throws Exception { boolean initialize = false; if (this.location == null) { this.directory = new RAMDirectory(); initialize = true;//ww w . ja v a2 s . c o m } else { File dir = new File(this.servletContext != null ? this.servletContext.getRealPath(location) : location); if (!dir.isDirectory()) { dir.mkdirs(); } LockFactory lf = (this.disableLocks ? NoLockFactory.getNoLockFactory() : null); this.directory = FSDirectory.open(dir, lf); log.info("Using lucene directory: file=" + dir + " instance=" + this.directory.toString()); initialize = (this.initializeIndexIfNew && dir.listFiles().length == 0); } if (initialize) { // create a dummy writer to initialize the index IndexWriter writer = null; try { writer = new IndexWriter(this.directory, new StandardAnalyzer(Version.LUCENE_30), true, MaxFieldLength.LIMITED); } finally { if (writer != null) { writer.close(); } } } }
From source file:ccc.plugins.search.lucene.SimpleLuceneFS.java
License:Open Source License
private Directory createDirectory() throws IOException { return FSDirectory.open(new java.io.File(_indexPath), new NativeFSLockFactory()); }
From source file:com.esri.gpt.catalog.lucene.LuceneIndexAdapter.java
License:Apache License
/** * Gets the Lucene Directory the has been configured to store the index. * @return the directory/* w ww . j av a2s. c o m*/ * @throws IOException if an exception occurs */ private Directory newDirectory() throws IOException { File fDir = new File(this.luceneConfig.getIndexLocation()); NativeFSLockFactory nativeLockFactory = this.getNativeLockFactory(); if (nativeLockFactory != null) { return FSDirectory.open(fDir, nativeLockFactory); } else { return FSDirectory.open(fDir); } }
From source file:com.esri.gpt.control.webharvest.engine.SourceUriArray.java
License:Apache License
/** * Creates instance of the collection./*w w w . j a v a 2s .co m*/ * @throws IOException if creating instance fails */ public SourceUriArray(String[] names) throws IOException { this.names = names != null ? names : new String[] {}; // get new UUID String name = UuidUtil.makeUuid(); // construct full path to the Lucene directory String path = System.getProperty("java.io.tmpdir") + File.separator + SUBFOLDER + File.separator + name; // create folder File folder = new File(path); folder.mkdirs(); // create Lucene directory within the folder; it has to be no locking directory directory = FSDirectory.open(folder, NoLockFactory.getNoLockFactory()); openForWriting(); }
From source file:com.esri.gpt.server.assertion.index.AsnBaseIndexAdapter.java
License:Apache License
/** * Gets the Lucene Directory assoctated with the index. * @return the directory// w w w . jav a2s.c o m * @throws IOException if an I/O exception occurs */ protected Directory getDirectory() throws IOException { File fDir = new File(this.getIndexReference().getIndexLocation()); NativeFSLockFactory nativeLockFactory = this.getNativeLockFactory(); if (nativeLockFactory != null) { return FSDirectory.open(fDir, nativeLockFactory); } else { return FSDirectory.open(fDir); } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public ArrayList getIndexNames() { IndexSearcher mainIndexSearcher = null; IndexReader ir = null;/* w ww. j a v a 2 s. c o m*/ try { ir = IndexReader.open(FSDirectory.open(new File(indexDir + File.separator + MAIN_INDEX), new SimpleFSLockFactory(indexDir + File.separator + MAIN_INDEX))); mainIndexSearcher = new IndexSearcher(ir); ArrayList<String[]> indexNames = new ArrayList<String[]>(); mainIndexSearcher = new IndexSearcher(ir); Query q = new WildcardQuery(new Term("indexName", "*")); TopScoreDocCollector collector = TopScoreDocCollector.create(10000, false); mainIndexSearcher.search(q, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (ScoreDoc hit : hits) { Document doc = mainIndexSearcher.doc(hit.doc); String indexName = doc.get("indexName"); String indexDisplayName = doc.get("displayName"); indexNames.add(new String[] { indexName, indexDisplayName }); } return indexNames; } catch (Exception ex) { ex.printStackTrace(); return null; } finally { try { ir.close(); mainIndexSearcher.close(); ir = null; mainIndexSearcher = null; } catch (IOException e) { logger.info("Error: Unable to close index."); System.exit(0); e.printStackTrace(); } } }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public ArrayList<CardSnapshot> getBookmarks() { ArrayList<CardSnapshot> cardSnaps = new ArrayList(); try {/* ww w . j ava 2s. c o m*/ IndexReader ir = IndexReader.open(FSDirectory.open(new File(indexDir + File.separator + MAIN_INDEX), new SimpleFSLockFactory(indexDir + File.separator + MAIN_INDEX))); IndexSearcher mainIndexSearcher = new IndexSearcher(ir); Query q = new WildcardQuery(new Term("qcId", "*")); TopScoreDocCollector collector = TopScoreDocCollector.create(10000, false); mainIndexSearcher.search(q, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (ScoreDoc hit : hits) { Document doc = mainIndexSearcher.doc(hit.doc); IndexReader reader = IndexReader .open(FSDirectory.open(new File(indexDir + File.separator + doc.get("qcIndexName")), new SimpleFSLockFactory(indexDir + File.separator + doc.get("qcIndexName")))); IndexSearcher searcher = new IndexSearcher(reader); q = new TermQuery(new Term("id", doc.get("qcId"))); collector = TopScoreDocCollector.create(10000, false); searcher.search(q, collector); ScoreDoc[] hits2 = collector.topDocs().scoreDocs; doc = searcher.doc(hits2[0].doc); cardSnaps.add(new CardSnapshot("", doc)); reader.close(); searcher.close(); reader = null; searcher = null; } ir.close(); mainIndexSearcher.close(); ir = null; mainIndexSearcher = null; } catch (Exception ex) { ex.printStackTrace(); } return cardSnaps; }
From source file:com.gauronit.tagmata.core.Indexer.java
License:Open Source License
public ArrayList<CardSnapshot> search(String searchText, ArrayList<String> indexNames, boolean searchInTitle, boolean searchInTags, boolean searchInText, boolean superFuzzy) { ArrayList<CardSnapshot> cardSnaps = new ArrayList(); try {//ww w. j av a2 s . co m ArrayList<IndexSearcher> searchers = new ArrayList<IndexSearcher>(); for (String indexName : indexNames) { IndexReader reader = IndexReader .open(FSDirectory.open(new File(indexDir + File.separator + indexName), new SimpleFSLockFactory(indexDir + File.separator + indexName))); IndexSearcher searcher = new IndexSearcher(reader); searchers.add(searcher); } BooleanQuery query = new BooleanQuery(); if (searchInTitle) { IndexerUtil.getTokenizedQuery(query, "title", searchText, superFuzzy); } if (searchInTags) { IndexerUtil.getTokenizedQuery(query, "tags", searchText, superFuzzy); } if (searchInText) { IndexerUtil.getTokenizedQuery(query, "text", searchText, superFuzzy); IndexerUtil.getTokenizedQuery(query, "analyzedText", searchText, superFuzzy); } for (IndexSearcher searcher : searchers) { TopScoreDocCollector collector = TopScoreDocCollector.create(10000, false); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (ScoreDoc hit : hits) { Document doc = searcher.doc(hit.doc); TokenStream stream = TokenSources.getTokenStream("text", doc.get("analyzedText"), new StandardAnalyzer(Version.LUCENE_20.LUCENE_35)); QueryScorer scorer = new QueryScorer(query, "analyzedText"); Fragmenter fragmenter = new SimpleSpanFragmenter(scorer, 20); Highlighter highlighter = new Highlighter(scorer); highlighter.setTextFragmenter(fragmenter); String[] fragments = highlighter.getBestFragments(stream, doc.get("text"), 5); String highlights = ""; for (String fragment : fragments) { highlights += fragment + "..."; } if (highlights.equals("")) { String text = doc.get("text"); if (text.length() > 100) { highlights += doc.get("text").substring(0, 100); } else { highlights += doc.get("text"); } } cardSnaps.add(new CardSnapshot(highlights, doc)); } searcher.getIndexReader().close(); searcher.close(); searcher = null; } } catch (Exception ex) { ex.printStackTrace(); } return cardSnaps; }
From source file:com.github.rnewson.couchdb.lucene.DatabaseIndexer.java
License:Apache License
private void init() throws IOException, JSONException { this.uuid = database.getOrCreateUuid(); this.context = Context.enter(); context.setClassShutter(new RestrictiveClassShutter()); context.setOptimizationLevel(9);// www . j av a 2 s . com this.ddoc_seq = database.getInfo().getUpdateSequence(); this.since = null; for (final DesignDocument ddoc : database.getAllDesignDocuments()) { for (final Entry<String, View> entry : ddoc.getAllViews().entrySet()) { final String name = entry.getKey(); final View view = entry.getValue(); paths.put(toPath(ddoc.getId(), name), view); if (!states.containsKey(view)) { final Directory dir = FSDirectory.open(viewDir(view, true), new SingleInstanceLockFactory()); final UpdateSequence seq = getUpdateSequence(dir); if (since == null) { since = seq; } since = seq.isEarlierThan(since) ? seq : since; logger.debug(dir + " bumped since to " + since); final DocumentConverter converter = new DocumentConverter(context, view); final IndexWriter writer = newWriter(dir); final IndexState state = new IndexState(converter, writer, view.getAnalyzer(), database, view); state.setPendingSequence(seq); states.put(view, state); } } } if (since == null) { since = UpdateSequence.START; } logger.debug("paths: " + paths); this.lastCommit = now(); latch.countDown(); }
From source file:com.github.tteofili.apacheconeu14.oak.search.nls.IndexUtils.java
License:Apache License
private static FSDirectory openDir() { try {//from w w w .ja v a 2s. c om File path = new File("/tmp/nls-lucene"); if (!path.exists()) { assert path.mkdirs(); } return FSDirectory.open(path, NoLockFactory.getNoLockFactory()); } catch (IOException e) { log.error("could not open /tmp/nls-lucene", e); } return null; }