Package org.apache.lucene.store

Examples of org.apache.lucene.store.RAMDirectory


    if (searchIndexProfile == null) {
      throw new NullPointerException("SearchIndexProfile is not defined");
    }
    // Loads custom data from a user-defined file.
    // Search index is created in a RAMDDirectory.
    customDataIndexDirectory = new RAMDirectory();
    String dataFile = searchIndexProfile.getSearchSuggestDataFile();
    if (dataFile != null) {
      try {
        initCustomDataIndex(dataFile, customDataIndexDirectory);
      } catch (Exception e) {
View Full Code Here


    /* Return early on cancellation */
    if (monitor.isCanceled() || Owl.isShuttingDown())
      return false;

    /* Need to index News and perform Searches */
    RAMDirectory directory = null;
    final IndexSearcher[] searcher = new IndexSearcher[1];
    if (needToIndex(enabledFilters)) {
      boolean indexDescription = needToIndexDescription(enabledFilters);
      directory = new RAMDirectory();
      directory.setLockFactory(NoLockFactory.getNoLockFactory());

      /* Index News */
      try {
        IndexWriter indexWriter = new IndexWriter(directory, Indexer.createAnalyzer());
        for (int i = 0; i < news.size(); i++) {

          /* Return early on cancellation */
          if (monitor.isCanceled() || Owl.isShuttingDown())
            return false;

          NewsDocument document = new NewsDocument(news.get(i));
          document.addFields(indexDescription);
          document.getDocument().getField(SearchDocument.ENTITY_ID_TEXT).setValue(String.valueOf(i));
          indexWriter.addDocument(document.getDocument());
        }
        indexWriter.close();

        searcher[0] = new IndexSearcher(directory);
      } catch (Exception e) {
        directory.close();
        throw e;
      }
    }

    /* Remember the news already filtered */
    List<INews> filteredNews = new ArrayList<INews>(news.size());
    boolean filterMatchedAll = false;

    /* Iterate over Filters */
    for (ISearchFilter filter : enabledFilters) {

      /* No Search Required */
      if (filter.getSearch() == null) {
        filterMatchedAll = true;

        List<INews> remainingNews = new ArrayList<INews>(news);
        remainingNews.removeAll(filteredNews);
        if (!remainingNews.isEmpty())
          applyFilter(filter, remainingNews);

        /* Done - we only support 1 filter per News */
        break;
      }

      /* Search Required */
      else if (directory != null && searcher[0] != null) {

        /* Return early if cancelled and nothing filtered yet */
        if ((monitor.isCanceled() || Owl.isShuttingDown()) && filteredNews.isEmpty())
          return false;

        try {
          final List<INews> matchingNews = new ArrayList<INews>(3);

          /* Perform Query */
          Query query = ModelSearchQueries.createQuery(filter.getSearch());
          searcher[0].search(query, new HitCollector() {
            @Override
            public void collect(int doc, float score) {
              try {
                Document document = searcher[0].doc(doc);
                int index = Integer.valueOf(document.get(SearchDocument.ENTITY_ID_TEXT));
                matchingNews.add(news.get(index));
              } catch (CorruptIndexException e) {
                Activator.getDefault().logError(e.getMessage(), e);
              } catch (IOException e) {
                Activator.getDefault().logError(e.getMessage(), e);
              }
            }
          });

          /* Apply Filter */
          matchingNews.removeAll(filteredNews);
          if (!matchingNews.isEmpty()) {
            applyFilter(filter, matchingNews);
            filteredNews.addAll(matchingNews);
          }
        } catch (IOException e) {
          directory.close();
          throw e;
        }
      }
    }

    /* Free RAMDirectory if it was built */
    if (directory != null)
      directory.close();

    return filterMatchedAll || !filteredNews.isEmpty();
  }
View Full Code Here

  cdoc = new ClassifyDoc();      docsProcessed = 0;  
  dbt = Constants.getDbt();

  //*-- create the RAM based Lucene IndexWriter
  analyzer = new StandardBgramAnalyzer(); analyzer.setExtractEntities(true);
  ramDir = new RAMDirectory(); //Similarity.setDefault(new SearchSimilarity());
  createRamIW();
  initTime +=  new Date().getTime();
}
View Full Code Here

  public FullTextIndex() {
    try {
      objects = new ArrayList();

      analyzer = new SimpleAnalyzer();
      indexDirectory = new RAMDirectory();
      indexWriter = new IndexWriter(indexDirectory,
          new IndexWriterConfig(Version.LUCENE_31,
              new LimitTokenCountAnalyzer(analyzer,
                  Integer.MAX_VALUE))
              .setOpenMode(OpenMode.CREATE));
View Full Code Here

    }
    return index;
  }
 
  private RAMDirectory createRAMIndex(Document doc) {
    RAMDirectory dir = new RAMDirectory();   
    IndexWriter writer = null;
    try {
      writer = new IndexWriter(dir, analyzer, true);
      writer.setMaxFieldLength(Integer.MAX_VALUE);
      writer.addDocument(doc);
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) {

    Directory ramDir = new RAMDirectory();
    try {
      IndexWriter writer = new IndexWriter(ramDir, /*new StandardAnalyzer()/*/XFactory.getWriterAnalyzer());
      Document doc = new Document();
      Field fd = new Field(FIELD_NAME, CONTENT, Field.Store.YES, Field.Index.TOKENIZED,Field.TermVector.WITH_POSITIONS_OFFSETS);
      doc.add(fd);
View Full Code Here

   
    //读取本类目录下的text.txt文件
    String content = ContentReader.readText(Chinese.class);

    //接下来是标准的Lucene建立索引和检索的代码
    Directory ramDir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(ramDir, analyzer, MaxFieldLength.UNLIMITED);
    Document doc = new Document();
    Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
        Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
    doc.add(fd);
View Full Code Here

   
    //读取本类目录下的text.txt文件
    String content = ContentReader.readText(English.class);

    //接下来是标准的Lucene建立索引和检索的代码
    Directory ramDir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(ramDir, analyzer, MaxFieldLength.UNLIMITED);
    Document doc = new Document();
    Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
        Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
    doc.add(fd);
View Full Code Here

    Directory directory = null;
    IndexWriter iwriter = null;
    IndexSearcher isearcher = null;
    try {
      //建立内存索引对象
      directory = new RAMDirectory();  
      iwriter = new IndexWriter(directory, analyzer, true , IndexWriter.MaxFieldLength.LIMITED);
      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);
View Full Code Here

   
    //读取本类目录下的text.txt文件
    String content = ContentReader.readText(Chinese.class);

    //接下来是标准的Lucene建立索引和检索的代码
    Directory ramDir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(ramDir, analyzer, MaxFieldLength.UNLIMITED);
    Document doc = new Document();
    Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
        Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
    doc.add(fd);
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.RAMDirectory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.