List of usage examples for org.apache.lucene.store RAMDirectory RAMDirectory
public RAMDirectory()
From source file:au.edu.unimelb.csse.join.JoinFunctionalTest.java
License:Apache License
public void testFilterjoin() throws Exception { String sent = "(NP" + "(NP" + "(DT The)" + "(NN year))" + "(NP" + "(NP(CD 1956))" + "(PP" + "(IN in)" + "(NP(JJ rugby)(NN union))" + ")" + ")" + "(. .)" + ")"; Analyzer analyser = new FastStringAnalyser(); RAMDirectory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, analyser, true, IndexWriter.MaxFieldLength.UNLIMITED); Document d = new Document(); d.add(new Field("sent", sent, Field.Store.NO, Field.Index.ANALYZED_NO_NORMS, Field.TermVector.WITH_POSITIONS)); writer.addDocument(d);/*w w w . j a va 2 s . c o m*/ writer.close(); IndexSearcher searcher = new IndexSearcher(dir); boolean[] lookaheadOptions = new boolean[] { false, true }; for (TermJoinType type : TermJoinType.values()) { for (boolean lookahead : lookaheadOptions) { QueryBuilder builder = new QueryBuilder("//PP[/IN AND /NP]"); TreebankQuery query = builder.parse(type, lookahead); SimpleHitCollector hitCollector = new SimpleHitCollector(10); searcher.search(query, hitCollector); assertEquals(1, hitCollector.totalHits); } } QueryBuilder builder = new QueryBuilder("//PP[/IN AND /NP/JJ/rugby]"); TreebankQuery query = builder.parse(TermJoinType.SIMPLE, true); SimpleHitCollector hitCollector = new SimpleHitCollector(10); searcher.search(query, hitCollector); assertEquals(1, hitCollector.totalHits); }
From source file:BlockBuilding.AbstractBlockBuilding.java
License:Apache License
protected void setMemoryDirectory() { indexDirectoryD1 = new RAMDirectory(); if (entityProfilesD2 != null) { indexDirectoryD2 = new RAMDirectory(); }// w ww . j a va2 s. c o m }
From source file:BlockBuilding.AbstractIndexBasedMethod.java
License:Open Source License
protected void setMemoryDirectory() { indexDirectory = new Directory[entityProfiles.length]; for (int i = 0; i < entityProfiles.length; i++) { indexDirectory[i] = new RAMDirectory(); }/*from w w w. j av a 2s. c om*/ }
From source file:br.pucminas.ri.jsearch.queryexpansion.RocchioQueryExpansion.java
License:Open Source License
private Directory createIndex(ArrayList<Document> relevantDocs) throws CorruptIndexException, LockObtainFailedException, IOException { Directory index = new RAMDirectory(); PorterStemAnalyzer analyzer = new PorterStemAnalyzer(); IndexWriterConfig conf = new IndexWriterConfig(analyzer); try (IndexWriter idxWriter = new IndexWriter(index, conf)) { for (Document d : relevantDocs) { idxWriter.addDocument(d);//www . j ava 2 s .c o m } } return index; }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.LuceneSearcher.java
License:Open Source License
public LuceneSearcher(String diretorio, String salvar, int topK, int stopword, String path) throws IOException, Exception { numQ = 1;/*from w ww.j a v a 2s . c o m*/ this.topK = topK; dir = new RAMDirectory(); // dir = new SimpleFSDirectory(new File("C:\\Users\\Silvio\\index\\")); a = new StandardAnalyzer(Version.LUCENE_36); System.out.println("Sem stop word"); }
From source file:byrne.mitre.main.NameMatcher.java
License:Apache License
public static void main(String[] args) { try {//w w w. j av a 2 s . co m long startTime = System.currentTimeMillis(); System.out.println("Loading Index..."); final Analyzer analyzer = new NGramAnalyzer(2, 4); final Directory index = new RAMDirectory(); final IndexWriter writer = new IndexWriter(index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); loadIndex("index.txt", writer); writer.close(); System.out.println("Running queries..."); final BufferedReader bufferedReader = new BufferedReader(new FileReader("queries.txt")); final BufferedWriter out = new BufferedWriter(new FileWriter("results.txt")); final IndexSearcher searcher = new IndexSearcher(index, true); String line = null; final int N_THREADS = Runtime.getRuntime().availableProcessors(); System.out.println("Total threads: " + N_THREADS); final ExecutorService executor = Executors.newFixedThreadPool(N_THREADS); while ((line = bufferedReader.readLine()) != null) { final NameEntry entry = new NameEntry(line); final MitreQuery q = new MitreQuery(entry, analyzer, searcher, out); executor.execute(q); } executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES); bufferedReader.close(); searcher.close(); out.close(); long endTime = System.currentTimeMillis(); System.out.println("Total run time: " + (endTime - startTime) / 60000 + " minutes"); } catch (IOException e) { System.out.println(e); } catch (InterruptedException e) { System.out.println(e); } }
From source file:ca.mcgill.cs.creco.logic.search.CategorySearch.java
License:Apache License
/** * Constructor.// ww w . j a v a 2 s .c o m * @param pDataStore The database whose categories will be in the search index. * @throws IOException If an exception is thrown during the creation of the product index. */ @Autowired public CategorySearch(IDataStore pDataStore) throws IOException { aDirectory = new RAMDirectory(); aAnalyzer = new EnglishAnalyzer(VERSION); aDataStore = pDataStore; buildCategoryIndex(); }
From source file:cc.osint.graphd.graph.Graph.java
License:Apache License
public Graph(String graphName) throws Exception { this.graphName = graphName; gr = new ListenableDirectedWeightedGraph<JSONVertex, JSONEdge>(JSONEdge.class); connectivityInspector = new ConnectivityInspector<JSONVertex, JSONEdge>(gr); vertices = new ConcurrentHashMap<String, JSONVertex>(); // event handlers gr.addVertexSetListener(this); gr.addGraphListener(this); gr.addVertexSetListener(connectivityInspector); gr.addGraphListener(connectivityInspector); // simulation components executorService = Executors.newCachedThreadPool(); fiberFactory = new PoolFiberFactory(executorService); vertexProcesses = new ProcessGroup<JSONVertex, JSONObject>(this, "vertex_processors", executorService, fiberFactory);//from ww w. j a va2 s . com edgeProcesses = new ProcessGroup<JSONEdge, JSONObject>(this, "edge_processors", executorService, fiberFactory); graphProcesses = new ProcessGroup<EventObject, JSONObject>(this, "graph_processors", executorService, fiberFactory); endpointChannelProcesses = new ProcessGroup<String, JSONObject>(this, "endpoint_channel_processors", executorService, fiberFactory); // graph index luceneDirectory = new RAMDirectory(); indexWriter = new IndexWriter(luceneDirectory, analyzer, IndexWriter.MaxFieldLength.LIMITED); indexReader = indexWriter.getReader(); searcher = new IndexSearcher(indexReader); // process registry simLuceneDirectory = new RAMDirectory(); simIndexWriter = new IndexWriter(simLuceneDirectory, analyzer, IndexWriter.MaxFieldLength.LIMITED); simIndexReader = simIndexWriter.getReader(); simSearcher = new IndexSearcher(simIndexReader); }
From source file:cc.pp.analyzer.ik.demo.IKAnalyzerDemo.java
License:Apache License
public static void main(String[] args) { //Lucene Document?? String fieldName = "text"; ///*from w w w.j a va 2 s. c o m*/ String text = "IK Analyzer???????"; //IKAnalyzer? Analyzer analyzer = new IKAnalyzer(Version.LUCENE_48, true); Directory directory = null; IndexWriter iwriter = null; DirectoryReader ireader = null; IndexSearcher isearcher = null; try { // directory = new RAMDirectory(); //?IndexWriterConfig IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_48, analyzer); iwConfig.setOpenMode(OpenMode.CREATE_OR_APPEND); iwriter = new IndexWriter(directory, iwConfig); // Document doc = new Document(); doc.add(new LongField("ID", 1000, Field.Store.YES)); doc.add(new TextField(fieldName, text, Field.Store.YES)); iwriter.addDocument(doc); iwriter.close(); //?********************************** //? ireader = DirectoryReader.open(directory); isearcher = new IndexSearcher(ireader); String keyword = "?"; // String keyword = ""; //QueryParser?Query QueryParser qp = new QueryParser(Version.LUCENE_48, fieldName, analyzer); qp.setDefaultOperator(QueryParser.AND_OPERATOR); Query query = qp.parse(keyword); System.out.println("Query = " + query); //?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:ch.algotrader.rest.index.SecurityIndexer.java
License:Open Source License
public SecurityIndexer() { this.index = new RAMDirectory(); this.securityCache = new ConcurrentHashMap<>(); }