Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexWriter


 
 
  Directory srcDir = FSDirectory.open(srcIdx);
  Directory targetDir = FSDirectory.open(targetIndx);
  int timesReplicatePerSeg = numReps/numsegs;
  IndexWriter writer = new IndexWriter(targetDir,new StandardAnalyzer(Version.LUCENE_CURRENT),MaxFieldLength.UNLIMITED);
  writer.setMaxMergeDocs(Integer.MAX_VALUE);
  writer.setMergeFactor(Integer.MAX_VALUE);
 
  System.out.println("num segments: "+numsegs);
  System.out.println("num reps per segment: "+timesReplicatePerSeg);
  for (int i=0;i<numsegs;++i){
    RAMDirectory ramDir = new RAMDirectory();
    IndexWriter subWriter = new IndexWriter(ramDir,new StandardAnalyzer(Version.LUCENE_CURRENT),MaxFieldLength.UNLIMITED);
    Directory[] multiplier = new Directory[timesReplicatePerSeg];
    for (int k=0;k<timesReplicatePerSeg;++k){
      multiplier[k]=new RAMDirectory(srcDir);
    }
    subWriter.addIndexesNoOptimize(multiplier);
    subWriter.optimize();
    subWriter.close();
 
    writer.addIndexesNoOptimize(new Directory[]{ramDir});
    System.out.println("segment: "+i+" created");
  }
 
View Full Code Here


   
  @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);
      writer.commit();
     
      PathFacetHandler pathHandler = new PathFacetHandler("path",true);
      facetHandlers.add(pathHandler);
  }
View Full Code Here

    } // fi   
    // *********************************************************************

    if (DebugFile.trace) DebugFile.writeln("new IndexWriter("+sDirectory+",[Analyzer], true)");

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);

    if (DebugFile.trace)
      DebugFile.writeln("DriverManager.getConnection(" + oProps.getProperty("dburl") + ", ...)");

    Connection oConn = DriverManager.getConnection(oProps.getProperty("dburl"), oProps.getProperty("dbuser"),oProps.getProperty("dbpassword"));

    Statement oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    ResultSet oRSet;

      PreparedStatement oRecp = oConn.prepareStatement("SELECT tx_personal,tx_email FROM k_inet_addrs WHERE tp_recipient<>'to' AND gu_mimemsg=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

      if (DebugFile.trace)
        DebugFile.writeln("Statement.executeQuery(SELECT m.gu_workarea,c.nm_category,m.gu_mimemsg,m.tx_subject,m.nm_from,m.tx_email_from,m.pg_message,m.de_mimemsg,m.dt_sent,m.len_mimemsg,m.by_content FROM k_mime_msgs m, k_categories c WHERE m.bo_deleted=0 AND m.bo_draft=0 AND m.gu_category=c.gu_category AND m.gu_workarea='"+sWorkArea+"' AND c.nm_category='"+sFolder+"')");

      oRSet = oStmt.executeQuery("SELECT m.gu_workarea,c.nm_category,m.gu_mimemsg,m.tx_subject,m.nm_from,m.tx_email_from,m.pg_message,m.de_mimemsg,m.dt_sent,m.len_mimemsg,m.by_content FROM k_mime_msgs m, k_categories c WHERE m.bo_deleted=0 AND m.bo_draft=0 AND m.gu_category=c.gu_category AND m.gu_workarea='"+sWorkArea+"' AND c.nm_category='"+sFolder+"'");

    int nIndexed = 0;

      while (oRSet.next()) {

        sWorkArea = oRSet.getString(1);
        sContainer = oRSet.getString(2);
        sGuid = oRSet.getString(3);
        sTitle = oRSet.getString(4);
        sAuthor = oRSet.getString(5);
        if (oRSet.wasNull()) sAuthor = "";
        sAuthor += " " + oRSet.getString(6);
        dNumber = oRSet.getBigDecimal(7);
        if (oRSet.wasNull()) dNumber = dZero;
        sComments = oRSet.getString(8);
        if (oRSet.wasNull()) sComments = "";
        dtCreated = oRSet.getDate(9);
        iSize = oRSet.getInt(10);

        if (DebugFile.trace) DebugFile.writeln("Indexing message "+sGuid+" - "+sTitle);

        InputStream oStrm = oRSet.getBinaryStream(11);

        String sRecipients = "";
        oRecp.setString(1, sGuid);
        ResultSet oRecs = oRecp.executeQuery();
        while (oRecs.next()) {
          String sTxPersonal = oRecs.getString(1);
          if (oRecs.wasNull())
            sRecipients += oRecs.getString(2)+" ";
          else
            sRecipients += oRecs.getString(1)+" "+oRecs.getString(2)+" ";
        } // wend
        oRecs.close();

        MailIndexer.addMail(oIWrt, sGuid, dNumber, sWorkArea, sContainer, sTitle,
                            sAuthor, sRecipients, dtCreated, sComments,
                            oStrm, iSize);
        nIndexed++;

      } // wend

      if (DebugFile.trace) {
        DebugFile.writeln(String.valueOf(nIndexed)+" messages indexed");
      }

      oRSet.close();
      oRecp.close();

    if (DebugFile.trace) {
      DebugFile.writeln("Statement.executeUpdate(UPDATE k_mime_msgs SET bo_indexed=1 WHERE gu_workarea='"+sWorkArea+"' AND gu_category IN (SELECT gu_category FROM k_categories WHERE nm_category='"+sFolder+"'))");
    }

    oStmt.executeUpdate("UPDATE k_mime_msgs SET bo_indexed=1 WHERE gu_workarea='"+sWorkArea+"' AND gu_category IN (SELECT gu_category FROM k_categories WHERE nm_category='"+sFolder+"')");

    oStmt.close();
    oConn.close();

    if (DebugFile.trace) DebugFile.writeln("IndexWriter.optimize()");

    oIWrt.optimize();

    if (DebugFile.trace) DebugFile.writeln("IndexWriter.close()");

    oIWrt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End MailIndexer.rebuildFolder()");
    }
View Full Code Here

      IndexReader oIRdr = IndexReader.open(sDirectory);
      oIRdr.deleteDocuments(new Term("guid",sGuid));
      oIRdr.close();
  }

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), bNewIndex);
 
  addNewsMessage(oIWrt, sGuid, sWorkArea, sContainer, sTitle, sAuthor, dtCreated, sText);
 
  oIWrt.close();
 
  } // addOrReplaceNewsMessage
View Full Code Here

       try { oFS.mkdirs(sDirectory); } catch (Exception e) { throw new IOException(e.getClass().getName()+" "+e.getMessage()); }
    }  // fi

    Class oAnalyzer = Class.forName(oProps.getProperty("analyzer" , DEFAULT_ANALYZER));

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);
    addBug(oIWrt, oCon, sWorkArea, oBug);
    oIWrt.close();
  } // addBug
View Full Code Here

    IndexReader oIRdr = IndexReader.open(sDirectory);
    oIRdr.deleteDocuments(new Term("guid", sGuid));
    oIRdr.close();

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer
        .newInstance(), bNewIndex);

    addDocument(oIWrt, sGuid, sWorkArea, oConn);

    oIWrt.close();

      if (DebugFile.trace) {
          DebugFile.decIdent();
          DebugFile.writeln("End ContactIndexer.addOrReplaceContact()");
      }
View Full Code Here

    Class oAnalyzer = Class.forName(oProps.getProperty("analyzer" , DEFAULT_ANALYZER));

    if (DebugFile.trace)
      DebugFile.writeln("new IndexWriter(...)");

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);

    if (DebugFile.trace) DebugFile.writeln("IndexWriter.optimize()");

    oIWrt.optimize();

    if (DebugFile.trace) DebugFile.writeln("IndexWriter.close()");

    oIWrt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Indexer.optimize()");
    }
View Full Code Here

    }
    // *********************************************************************

    if (DebugFile.trace) DebugFile.writeln("new IndexWriter("+sDirectory+",[Analyzer], true)");

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);

    if (DebugFile.trace)
      DebugFile.writeln("DriverManager.getConnection(" + oProps.getProperty("dburl") + ", ...)");

    Connection oConn = DriverManager.getConnection(oProps.getProperty("dburl"), oProps.getProperty("dbuser"),oProps.getProperty("dbpassword"));
    oConn.setAutoCommit(true);

    Statement oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    ResultSet oRSet;

    if (sTableName.equalsIgnoreCase("k_bugs")) {

      if (DebugFile.trace)
        DebugFile.writeln("Statement.executeQuery(SELECT p.gu_workarea,p.nm_project,b.gu_bug,b.tl_bug,b.dt_modified," + IfNull(oConn) + "(b.nm_reporter,'')," + IfNull(oConn) + "(b.tx_bug_brief,'')," + IfNull(oConn) + "(b.tx_comments,'') FROM k_bugs b, k_projects p WHERE b.gu_project=p.gu_project AND p.gu_owner='"+sWorkArea+"')");

      oRSet = oStmt.executeQuery("SELECT p.gu_owner,p.nm_project,b.gu_bug,b.pg_bug,b.tl_bug,b.dt_modified," + IfNull(oConn) + "(b.nm_reporter,'')," + IfNull(oConn) + "(b.tx_comments,'')," + IfNull(oConn) + "(b.tx_bug_brief,'') FROM k_bugs b, k_projects p WHERE b.gu_project=p.gu_project AND p.gu_owner='"+sWorkArea+"'");

      while (oRSet.next()) {
        sWorkArea = oRSet.getString(1);
        sContainer = oRSet.getString(2);
        sGuid = oRSet.getString(3);
        iNumber = oRSet.getInt(4);
        sTitle = oRSet.getString(5);
        dtCreated = oRSet.getDate(6);
        sAuthor = oRSet.getString(7);
        sComments = oRSet.getString(8);
        if (null==sComments) sComments = "";
        sText = oRSet.getString(9);
        if (null==sText) sText = "";
        BugIndexer.addBug(oIWrt, sGuid, iNumber, sWorkArea, sContainer, sTitle, sAuthor, dtCreated, sComments, sText);
      } // wend
      oRSet.close();
    }

    else if (sTableName.equalsIgnoreCase("k_newsmsgs")) {

      if (DebugFile.trace)
        DebugFile.writeln("Statement.executeQuery(SELECT g.gu_workarea,c.nm_category,m.gu_msg,m.tx_subject,m.dt_published," + IfNull(oConn) + "(b.nm_author,'')," + IfNull(oConn) + "(b.tx_msg,'') FROM k_newsmsgs m, k_categories c, k_newsgroups g, k_x_cat_objs x WHERE m.id_status=0 AND m.gu_msg=x.gu_object AND x.gu_category=g.gu_newsgrp AND c.gu_category=g.gu_newsgrp AND g.gu_workarea='"+sWorkArea+"')");

      oRSet = oStmt.executeQuery("SELECT g.gu_workarea,c.nm_category,m.gu_msg,m.tx_subject,m.dt_published," + IfNull(oConn) + "(m.nm_author,'')," + IfNull(oConn) + "(m.tx_msg,'') FROM k_newsmsgs m, k_categories c, k_newsgroups g, k_x_cat_objs x WHERE m.id_status=0 AND m.gu_msg=x.gu_object AND x.gu_category=g.gu_newsgrp AND c.gu_category=g.gu_newsgrp AND g.gu_workarea='"+sWorkArea+"'");

      while (oRSet.next()) {
        sWorkArea = oRSet.getString(1);
        sContainer = oRSet.getString(2);
        sGuid = oRSet.getString(3);
        sTitle = oRSet.getString(4);
        dtCreated = oRSet.getDate(5);
        sAuthor = oRSet.getString(6);
        sText = oRSet.getString(7);
        NewsMessageIndexer.addNewsMessage(oIWrt, sGuid, sWorkArea, sContainer, sTitle, sAuthor, dtCreated, sText);
      } // wend
      oRSet.close();
    }
    // Inicio I2E 2009-12-23
    else if (sTableName.equalsIgnoreCase("k_contacts")) {
     
      Map<String,ContactRecord> contacts = new HashMap<String,ContactRecord>();
      String consultas[] = new String[6];
      consultas[0] = "SELECT c.gu_contact, c.gu_workarea, c.tx_name, c.tx_surname, csc.nm_scourse, csc.lv_scourse FROM k_contacts c, k_contact_short_courses csc WHERE c.gu_workarea='" + sWorkArea + "' AND csc.gu_contact = c.gu_contact";
      consultas[1] = "SELECT c.gu_contact, c.gu_workarea, c.tx_name, c.tx_surname, ccsl.tr_es,ccsl2.tr_es FROM k_contacts c, k_contact_computer_science ccc, k_contact_computer_science_lookup ccsl, k_contact_computer_science_lookup ccsl2 WHERE c.gu_workarea='"+ sWorkArea +"' AND ccc.gu_contact = c.gu_contact AND ccc.nm_skill = ccsl.vl_lookup AND ccc.lv_skill = ccsl2.vl_lookup";
      consultas[2] = "SELECT c.gu_contact, c.gu_workarea, c.tx_name, c.tx_surname, ccsl.tr_en,ccsl2.tr_en FROM k_contacts c, k_contact_computer_science ccc, k_contact_computer_science_lookup ccsl, k_contact_computer_science_lookup ccsl2 WHERE c.gu_workarea='"+ sWorkArea +"' AND ccc.gu_contact = c.gu_contact AND ccc.nm_skill = ccsl.vl_lookup AND ccc.lv_skill = ccsl2.vl_lookup";
      consultas[3] = "SELECT c.gu_contact, c.gu_workarea, c.tx_name, c.tx_surname, ed.nm_degree,'' as level FROM k_contacts c,k_contact_education ce,k_education_degree ed WHERE c.gu_workarea='"+ sWorkArea +"' AND ce.gu_contact = c.gu_contact AND ce.gu_degree= ed.gu_degree";
      consultas[4] = "SELECT c.gu_contact, c.gu_workarea, c.tx_name, c.tx_surname, ll.tr_lang_es,cll.tr_es FROM k_contacts c, k_contact_languages cl, k_lu_languages ll,k_contact_languages_lookup cll WHERE c.gu_workarea='"+ sWorkArea +"' AND c.gu_contact = cl.gu_contact AND cl.id_language = ll.id_language AND cl.lv_language_degree = cll.vl_lookup";
      consultas[5] = "SELECT c.gu_contact, c.gu_workarea, c.tx_name, c.tx_surname, ll.tr_lang_en,cll.tr_en FROM k_contacts c, k_contact_languages cl, k_lu_languages ll,k_contact_languages_lookup cll WHERE c.gu_workarea='"+ sWorkArea +"' AND c.gu_contact = cl.gu_contact AND cl.id_language = ll.id_language AND cl.lv_language_degree = cll.vl_lookup";
     
      for(int i=0;i<consultas.length;i++){
            if (DebugFile.trace)
                DebugFile.writeln("Statement.executeQuery(" + consultas[i] + ")");

        oRSet = oStmt.executeQuery(consultas[i]);

          while (oRSet.next()) {
              sGuid = oRSet.getString(1);
              sWorkArea = oRSet.getString(2);
              String sName = oRSet.getString(3);
              String sSurname = oRSet.getString(4);
              String sValue = oRSet.getString(5);
              String sLevel = oRSet.getString(6);
              if(sLevel==null) sLevel="";
              ContactRecord contact = contacts.get(sGuid);
              if(contact==null){
                contact = new ContactRecord(null,sName+" "+ sSurname,sWorkArea,sGuid);
                contacts.put(sGuid, contact);
              }
              contact.addValue(sValue, sLevel);

              //ContactIndexer.addDocument(oIWrt, sGuid, sWorkArea, sName, sSurname, ContactRecord.COURSE, sValue, sLevel,null);
             
            }
          oRSet.close();
      }
      ContactRecord arrayContactos[] = contacts.values().toArray(new ContactRecord[contacts.size()]);
      for(int i=0;i<arrayContactos.length;i++){
        ContactIndexer.addDocument(oIWrt,arrayContactos[i]);
      }
     
     
      }
    //Fin i2E
      else if (sTableName.equalsIgnoreCase("k_mime_msgs")) {

      LinkedList oIndexedGuids = new LinkedList();

      PreparedStatement oRecp = oConn.prepareStatement("SELECT tx_personal,tx_email FROM k_inet_addrs WHERE tp_recipient<>'to' AND gu_mimemsg=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

      if (DebugFile.trace)
        DebugFile.writeln("Statement.executeQuery(SELECT g.gu_workarea,c.nm_category,m.gu_mimemsg,m.tx_subject,m.nm_from,m.tx_mail_from,m.pg_mimemsg,m.de_mimemsg,m.dt_sent,m.len_mimemsg,m.by_content FROM k_mime_msgs m, k_categories c WHERE m.bo_deleted<>0 AND m.bo_draft<>0 AND m.gu_category=c.gu_category AND m.gu_workarea='"+sWorkArea+"')");

      oRSet = oStmt.executeQuery("SELECT g.gu_workarea,c.nm_category,m.gu_mimemsg,m.tx_subject,m.nm_from,m.tx_mail_from,m.pg_mimemsg,m.de_mimemsg,m.dt_sent,m.len_mimemsg,m.by_content FROM k_mime_msgs m, k_categories c WHERE m.bo_deleted<>0 AND m.bo_draft<>0 AND m.gu_category=c.gu_category AND m.gu_workarea='"+sWorkArea+"'");

      while (oRSet.next()) {

        sWorkArea = oRSet.getString(1);
        sContainer = oRSet.getString(2);
        sGuid = oRSet.getString(3);
        sTitle = oRSet.getString(4);
        sAuthor = oRSet.getString(5);
        if (oRSet.wasNull()) sAuthor = "";
        sAuthor += " " + oRSet.getString(6);
        dNumber = oRSet.getBigDecimal(7);
        if (oRSet.wasNull()) dNumber = dZero;
        sComments = oRSet.getString(8);
        dtCreated = oRSet.getDate(9);
        iSize = oRSet.getInt(10);

        if (DebugFile.trace) DebugFile.writeln("Indexing message "+sGuid+" - "+sTitle);

        InputStream oStrm = oRSet.getBinaryStream(11);

        String sRecipients = "";
        oRecp.setString(1, sGuid);
        ResultSet oRecs = oRecp.executeQuery();
        while (oRecs.next()) {
          sRecipients += oRecs.getString(1)+" "+oRecs.getString(2)+" ";
        } // wend
        oRecs.close();

        MailIndexer.addMail(oIWrt, sGuid, dNumber, sWorkArea, sContainer, sTitle,
                            sAuthor, sRecipients, dtCreated, sComments, oStrm, iSize);

        oIndexedGuids.add(sGuid);
      } // wend
      oRSet.close();
      oRecp.close();

      PreparedStatement oUpdt = oConn.prepareStatement("UPDATE k_mime_msgs SET bo_indexed=1 WHERE gu_mimemsg=?");
      ListIterator oIter = oIndexedGuids.listIterator();
      while (oIter.hasNext()) {
        oUpdt.setObject(1, oIter.next(), java.sql.Types.CHAR);
        oUpdt.executeUpdate();
      } // wend
      oUpdt.close();
    } // fi

    oStmt.close();
    oConn.close();

    if (DebugFile.trace) DebugFile.writeln("IndexWriter.optimize()");

    oIWrt.optimize();

    if (DebugFile.trace) DebugFile.writeln("IndexWriter.close()");

    oIWrt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Indexer.rebuild()");
    }
View Full Code Here

      try { oFS.mkdirs(sDirectory); } catch (Exception e) { throw new IOException(e.getClass().getName()+" "+e.getMessage()); }
    }

    Class oAnalyzer = Class.forName((sAnalyzer==null) ? DEFAULT_ANALYZER : sAnalyzer);

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);

    add (oIWrt, oKeywords, oTexts, oUnStored);

    oIWrt.close();
  } // add
View Full Code Here

    oTexts.put("abstract", sAbstract==null ? "" : Gadgets.left(sAbstract, 80));
    HashMap oUnstor = new HashMap(11);
    oUnstor.put("comments", sComments==null ? "" : sComments);
    oUnstor.put("text", sText==null ? "" : sText);

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);
    add(oIWrt, oKeys, oTexts, oUnstor);
    oIWrt.close();
  } // add
View Full Code Here

TOP

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

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.