Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexWriter$Num


    Document doc = new Document();
    doc.add(new Field("id", "1", Field.Store.YES, Field.Index.UN_TOKENIZED));
    doc.add(new Field("author", "����IBM OSIһһ����", Field.Store.YES, Field.Index.TOKENIZED));
    doc.add(new Field("time", Long.toString(System.currentTimeMillis()), Field.Store.YES, Field.Index.UN_TOKENIZED));
    doc.add(new Field("content", "��֪����ʲôʱ��ʼ����ʲô�������涼�и����ڣ��ﵶ�����ڣ����ͷ����ڣ�������ֽ������ڣ��ҿ�ʼ���ɣ�����������ϣ�����ʲô�����Dz�����ڵģ�", Field.Store.NO, Field.Index.TOKENIZED));
    IndexWriter writer = getWriter();
    try {
        writer.addDocument(doc);
        writer.optimize();
    }finally {
        writer.close();
    }
    System.out.println("doc count = " + writer.docCount());
        return 1;
    }
View Full Code Here


      }
      wc++;
        }
        File segments = new File(lucenePath + File.separator + SEGMENTS);
        boolean bCreate = !segments.exists();
        return new IndexWriter(lucenePath,new StandardAnalyzer(),bCreate);
    }
View Full Code Here

    for(int i=0;indexFields!=null && i<indexFields.length;i++){
      String propertyValue = getField(doc, indexFields[i]);
      lucene_doc.add(UnStored(indexFields[i], propertyValue));
    }
    //Write document
    IndexWriter writer = getWriter(doc.name());
    try {
        writer.addDocument(lucene_doc);
        writer.optimize();
    }finally {
      try{
        writer.close();
      }catch(Exception e){
        log.error("Error occur when closing IndexWriter", e);
      }finally{
        writer = null;
      }
View Full Code Here

        path.append(File.separator);
        path.append(SEGMENTS);
        File segments = new File(path.toString());
        try{
          boolean bCreate = !segments.exists();
          return new IndexWriter(index_path,new StandardAnalyzer(),bCreate);
        }finally{
          path = null;
          segments = null;
          rp = null;
        }
View Full Code Here

    try {
      indexName = indexFile.getCanonicalPath();
      directory = FSDirectory.getDirectory(indexName);
      if (create) {
        log.debug("Initialize index: '" + indexFile + "'");
        IndexWriter iw = new IndexWriter(directory,
            new StandardAnalyzer(), create);
        iw.close();
      }
    } catch (IOException e) {
      throw new HibernateException("Unable to initialize index: "
          + indexFile, e);
    }
View Full Code Here

                    //## LUCENE3 begin ##
                    File f = new File(path);
                    Directory indexDir = FSDirectory.open(f);
                    boolean recreate = !IndexReader.indexExists(indexDir);
                    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
                    IndexWriter writer = new IndexWriter(indexDir, analyzer,
                            recreate, IndexWriter.MaxFieldLength.UNLIMITED);
                    //see http://wiki.apache.org/lucene-java/NearRealtimeSearch
                    IndexReader reader = writer.getReader();
                    access = new IndexAccess();
                    access.writer = writer;
                    access.reader = reader;
                    access.searcher = new IndexSearcher(reader);
                    //## LUCENE3 end ##
View Full Code Here

                String       botname = resultSet.getString("botname").toLowerCase();
                String       channel = resultSet.getString("channel").substring(1).toLowerCase();
                String       key = getIndexName(botname, servername, channel);
                Document     doc = new Document();
                Timestamp     moment = resultSet.getTimestamp("moment");
                IndexWriter   writer = (IndexWriter)index_writer_cache.get(key);

                if (writer == null)
                {
                  writer = getIndexWriter(key, true);

                  index_writer_cache.put(key, writer);
                }

                beginningOfDay.setTime(moment);
                beginningOfDay.setTimeZone(TimeZone.getTimeZone(DroneConfig.getTimezone()));
                beginningOfDay.set(Calendar.HOUR, 0);
                beginningOfDay.set(Calendar.MINUTE, 0);
                beginningOfDay.set(Calendar.SECOND, 0);
                beginningOfDay.set(Calendar.MILLISECOND, 0);

                long dayInMillis = beginningOfDay.getTimeInMillis();
                long timeInMillis = moment.getTime() - dayInMillis;

                // need to store channel without the '#'
                doc.add(new Field("moment", DateField.dateToString(resultSet.getTimestamp("moment")), true, true, true));
                doc.add(new Field("momentDateSort", String.valueOf(dayInMillis), false, true, false));
                doc.add(new Field("momentTimeSort", String.valueOf(timeInMillis), false, true, false));
                doc.add(new Field("botname", botname, true, true, true));
                doc.add(new Field("channel", channel, true, true, true));
                doc.add(new Field("servername", servername, true, true, true));
                doc.add(new Field("nickname", resultSet.getString("nickname"), true, true, true));
                doc.add(new Field("username", resultSet.getString("username"), true, true, true));
                doc.add(new Field("hostname", resultSet.getString("hostname"), true, true, true));
                doc.add(new Field("message", resultSet.getString("message"), true, true, true));

                try
                {
                  writer.addDocument(doc, getAnalyzer());
                }
                catch (IOException e)
                {
                  Logger
                    .getLogger("com.uwyn.drone.tools")
View Full Code Here

        indexArticle( article );
    }

    private void indexArticle(Article article) throws IOException {
        Document doc = article.getOveriewDocument();
        IndexWriter writer = new IndexWriter( forum.getArticleOverview(), ws, true );
        writer.addDocument( doc );
        writer.close();
    }
View Full Code Here

 
  public void testIndexReaderReopen() throws Exception{
    Directory idxDir = new RAMDirectory();
    Document[] docs = buildData();
   
    IndexWriter writer = new IndexWriter(idxDir,new StandardAnalyzer(Version.LUCENE_29),MaxFieldLength.UNLIMITED);
    writer.addDocument(docs[0]);
    writer.optimize();
    writer.commit();
   
    IndexReader idxReader = IndexReader.open(idxDir,true);
    BoboIndexReader boboReader = BoboIndexReader.getInstance(idxReader,_fconf);

   
    for (int i=1;i<docs.length;++i){
      Document doc = docs[i];
      int numDocs = boboReader.numDocs();
      BoboIndexReader reader = (BoboIndexReader)boboReader.reopen(true);
      assertSame(boboReader,reader);
     
      Directory tmpDir = new RAMDirectory();
      IndexWriter subWriter = new IndexWriter(tmpDir,new StandardAnalyzer(Version.LUCENE_29),MaxFieldLength.UNLIMITED);
      subWriter.addDocument(doc);
      subWriter.optimize();
      subWriter.close();
      writer.addIndexesNoOptimize(new Directory[]{tmpDir});
      writer.commit();
      reader = (BoboIndexReader)boboReader.reopen();
      assertNotSame(boboReader, reader);
      assertEquals(numDocs+1,reader.numDocs());
View Full Code Here

  {
    List<FacetHandler<?>> facetHandlers = new ArrayList<FacetHandler<?>>();
    /* Underlying time facet for DynamicTimeRangeFacetHandler */
    facetHandlers.add(new RangeFacetHandler("timeinmillis", new PredefinedTermListFactory(Long.class, DynamicTimeRangeFacetHandler.NUMBER_FORMAT),null));
    Directory idxDir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(idxDir,new StandardAnalyzer(Version.LUCENE_29),MaxFieldLength.UNLIMITED);
   
    long now = System.currentTimeMillis();
    DecimalFormat df = new DecimalFormat(DynamicTimeRangeFacetHandler.NUMBER_FORMAT);
    for(long l=0; l<53; l++)
    {
      Document d = new Document();
      d.add(buildMetaField("timeinmillis", df.format(now - l*3500000)));
      writer.addDocument(d);
      writer.optimize();
      writer.commit();
    }
    IndexReader idxReader = IndexReader.open(idxDir,true);
    BoboIndexReader boboReader = BoboIndexReader.getInstance(idxReader,facetHandlers);
    BoboBrowser browser = new BoboBrowser(boboReader);
    List<String> ranges = new ArrayList<String>();
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexWriter$Num

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.