List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory
public RAMDirectory()
From source file:com.browseengine.bobo.test.FacetNotValuesTest.java
License:Open Source License
private Directory createIndexTwo() { Directory dir = new RAMDirectory(); try {// w ww .ja v a 2s. c o m Document[] data = createDataTwo(); TestDataDigester testDigester = new TestDataDigester(_facetHandlers, data); BoboIndexer indexer = new BoboIndexer(testDigester, dir); indexer.index(); IndexReader r = IndexReader.open(dir, false); r.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return dir; }
From source file:com.browseengine.bobo.test.section.TestSectionSearch.java
License:Apache License
protected void setUp() throws Exception { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED); addDoc("1", new String[] { "aa", "bb" }, new String[] { "aaa", "aaa" }, new int[] { 100, 200 }); addDoc("2", new String[] { "aa", "bb" }, new String[] { "aaa", "bbb" }, new int[] { 200, 200 }); addDoc("3", new String[] { "aa", "bb" }, new String[] { "bbb", "aaa" }, new int[] { 300, 300 }); addDoc("3", new String[] { "bb", "aa" }, new String[] { "bbb", "bbb" }, new int[] { 300, 400 }); addDoc("3", new String[] { "bb", "aa" }, new String[] { "aaa", "ccc" }, new int[] { 300, 500 }); writer.commit();// w ww. j a v a 2 s .c om IndexReader reader = IndexReader.open(directory, true); searcher = new IndexSearcher(reader); IndexReader readerWithCache = new IndexReaderWithMetaDataCache(reader); searcherWithCache = new IndexSearcher(readerWithCache); }
From source file:com.browseengine.bobo.test.TestPathMultiVal.java
License:Apache License
@Override protected void setUp() throws Exception { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); IndexWriter writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED); Document doc = new Document(); addMetaDataField(doc, PathHandlerName, new String[] { "/a/b/c", "/a/b/d" }); writer.addDocument(doc);/*from ww w . j a va2s. c om*/ writer.commit(); PathFacetHandler pathHandler = new PathFacetHandler("path", true); facetHandlers.add(pathHandler); }
From source file:com.browseengine.local.service.geoindex.test.GeoResourceWriterTest.java
License:Open Source License
public void testWrite() throws Throwable { GeoResourceWriter writer = null;/*from ww w. j av a2s. c o m*/ try { RAMDirectory ramDir = new RAMDirectory(); writer = new GeoResourceWriter(ramDir, true); LocalResource resource = new LocalResource("Spackle Me", "A place to go to get spackle.", "123 Fake St., Springfiled, ??", 4155551212L, -101., 45.1, 1); writer.addResource(resource); resource = new LocalResource("Bobo Foobar", "A place where you can hop to it.", "321 Singleton Ave., Chicago, IL 01123", 4155555785L, -95, 40, 2); writer.addResource(resource); try { resource = new LocalResource("Bad Record", "This record should never make the index", "The Moon, Alice!", 4155559292L, -200, 22, 100); writer.addResource(resource); fail("should have thrown an exception for an out-of-range resource, but didn't"); } catch (GeoIndexingException gie) { // okay } writer.optimize(); writer.close(); writer = null; LOGGER.info(getName() + ": success!"); } catch (Throwable t) { LOGGER.error("fail: " + t, t); throw t; } finally { if (writer != null) { writer.close(); } } }
From source file:com.bull.aurocontrol.csst.poc.index.interval.BaseIntervalQueryTest.java
License:Apache License
@Before public void setUp() throws IOException { RAMDirectory ramDirectory = new RAMDirectory(); indexWriter = new IndexWriter(ramDirectory, new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()).setOpenMode(OpenMode.CREATE)); }
From source file:com.codecrate.shard.search.RAMDirectoryManager.java
License:Apache License
public RAMDirectoryManager() throws IOException { this.directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(), true); writer.close();/*from w w w. ja va 2 s . c o m*/ }
From source file:com.common.search.IKAnalyzerDemo.java
License:Apache License
public static void main(String[] args) { // Lucene Document String fieldName = "text"; // /*from ww w.j av a 2 s. com*/ String text = "IK Analyzer "; // IKAnalyzer Analyzer analyzer = new IKAnalyzer(); Directory directory = null; IndexWriter iwriter = null; IndexReader ireader = null; IndexSearcher isearcher = null; try { // directory = new RAMDirectory(); // IndexWriterConfig IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_34, analyzer); iwConfig.setOpenMode(OpenMode.CREATE_OR_APPEND); iwriter = new IndexWriter(directory, iwConfig); // Document doc = new Document(); doc.add(new Field("ID", "10000", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field(fieldName, text, Field.Store.YES, Field.Index.ANALYZED)); iwriter.addDocument(doc); iwriter.close(); // ********************************** // ireader = IndexReader.open(directory); isearcher = new IndexSearcher(ireader); String keyword = ""; // QueryParserQuery QueryParser qp = new QueryParser(Version.LUCENE_34, fieldName, analyzer); qp.setDefaultOperator(QueryParser.AND_OPERATOR); Query query = qp.parse(keyword); // 5 TopDocs topDocs = isearcher.search(query, 5); System.out.println(" " + topDocs.totalHits); // ScoreDoc[] scoreDocs = topDocs.scoreDocs; for (int i = 0; i < topDocs.totalHits; i++) { Document targetDoc = isearcher.doc(scoreDocs[i].doc); System.out.println(" " + targetDoc.toString()); } } catch (CorruptIndexException e) { e.printStackTrace(); } catch (LockObtainFailedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } finally { if (ireader != null) { try { ireader.close(); } catch (IOException e) { e.printStackTrace(); } } if (directory != null) { try { directory.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.concursive.connect.indexer.AbstractLuceneTest.java
License:Open Source License
protected void setUp() throws Exception { // Snowball/*from w w w . j ava 2 s. com*/ snowballAnalyzer = new SnowballAnalyzer("English"); snowballIndex = new RAMDirectory(); snowballWriter = new IndexWriter(snowballIndex, snowballAnalyzer, true); // Standard standardAnalyzer = new StandardAnalyzer(); standardIndex = new RAMDirectory(); standardWriter = new IndexWriter(standardIndex, standardAnalyzer, true); }
From source file:com.concursive.connect.indexer.LuceneIndexer.java
License:Open Source License
/** * Sets up any Lucene Indexer classes//from w w w.ja v a 2 s. com * * @param context * @return * @throws Exception */ public boolean setup(IndexerContext context) throws Exception { // Make sure the complex queries can use more than the default clause count BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); // Setup the Indexes so they are in a state in which they can immediately // be accessed ApplicationPrefs prefs = context.getApplicationPrefs(); { // Establish the full directory LOG.info("Starting Lucene disk index"); File path = new File(prefs.get("FILELIBRARY") + Constants.FULL_INDEX); boolean create = !path.exists(); fullIndex = FSDirectory.getDirectory(prefs.get("FILELIBRARY") + Constants.FULL_INDEX); if (create) { LOG.warn("Lucene index not found, creating new index: " + path.getPath()); Analyzer fullAnalyzer = new StandardAnalyzer(); fullWriter = new IndexWriter(fullIndex, fullAnalyzer, true); fullWriter.close(); } } { // Load up the ram directory LOG.info("Creating Lucene RAM index..."); // Create the Ram Directory directoryIndex = new RAMDirectory(); Analyzer directoryAnalyzer = new SnowballAnalyzer("English"); directoryWriter = new IndexWriter(directoryIndex, directoryAnalyzer, true); directoryWriter.close(); LOG.info("Initialization of RAM index complete..."); } // Search using the updated index resetSearchers(); return true; }
From source file:com.czw.search.lucene.example.xmlparser.FormBasedXmlQueryDemo.java
License:Apache License
private void openExampleIndex() throws IOException { //Create a RAM-based index from our test data file RAMDirectory rd = new RAMDirectory(); IndexWriterConfig iwConfig = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(rd, iwConfig); InputStream dataIn = getServletContext().getResourceAsStream("/WEB-INF/data.tsv"); BufferedReader br = new BufferedReader(new InputStreamReader(dataIn, StandardCharsets.UTF_8)); String line = br.readLine();//from w w w . ja va2s.com final FieldType textNoNorms = new FieldType(TextField.TYPE_STORED); textNoNorms.setOmitNorms(true); while (line != null) { line = line.trim(); if (line.length() > 0) { //parse row and create a document StringTokenizer st = new StringTokenizer(line, "\t"); Document doc = new Document(); doc.add(new Field("location", st.nextToken(), textNoNorms)); doc.add(new Field("salary", st.nextToken(), textNoNorms)); doc.add(new Field("type", st.nextToken(), textNoNorms)); doc.add(new Field("description", st.nextToken(), textNoNorms)); writer.addDocument(doc); } line = br.readLine(); } writer.close(); //open searcher // this example never closes it reader! IndexReader reader = DirectoryReader.open(rd); searcher = new IndexSearcher(reader); }