Package org.apache.lucene.document

Examples of org.apache.lucene.document.Document


    /**
     * ��������
     */
    protected static int addIndex() throws IOException {
    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 {
View Full Code Here


   */
  public static synchronized void add(SearchEnabled doc) throws Exception {
    if(doc == null)
      return ;

    Document lucene_doc = new Document();
   
    //Set keyword field
    String key = getField(doc, doc.getKeywordField());
    lucene_doc.add(Keyword(doc.getKeywordField(), key));
   
    //Set identity(classname) of object
    lucene_doc.add(Keyword(CLASSNAME_FIELD, doc.getClass().getName()));
   
    //Set storage field
    String[] storeFields = doc.getStoreFields();
    for(int i=0;storeFields!=null && i<storeFields.length;i++){
      String propertyValue = getField(doc, storeFields[i]);
      if(propertyValue!=null)
        lucene_doc.add(Keyword(storeFields[i], propertyValue));
    }
    //Set indexed field
    String[] indexFields = doc.getIndexFields();
    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);
View Full Code Here

    int numResults = hits.length();
    //System.out.println(numResults + " found............................");
    int result_count = Math.min(numResults, MAX_RESULT_COUNT);
    List results = new ArrayList(result_count);
    for(int i=0;i<result_count;i++){
      Document doc = (Document)hits.doc(i);
      //ӳ���ĵ����Ե�Java������
      Object result = params.getSearchObject().newInstance();
      Enumeration fields = doc.fields();
      while(fields.hasMoreElements()){
        Field field = (Field)fields.nextElement();
        //System.out.println(field.name()+" -- "+field.stringValue());
        if(CLASSNAME_FIELD.equals(field.name()))
          continue;
View Full Code Here

            }
            for (int i = 0, len = docs.scoreDocs.length;
                    i < limit && i + offset < docs.totalHits
                    && i + offset < len; i++) {
                ScoreDoc sd = docs.scoreDocs[i + offset];
                Document doc = searcher.doc(sd.doc);
                float score = sd.score;
                //## LUCENE3 end ##
                String q = doc.get(LUCENE_FIELD_QUERY);
                if (data) {
                    int idx = q.indexOf(" WHERE ");
                    JdbcConnection c = (JdbcConnection) conn;
                    Session session = (Session) c.getSession();
                    Parser p = new Parser(session);
View Full Code Here

                throw convertException(e);
            }
            ## LUCENE2 end ##*/
            //## LUCENE3 begin ##
            String query = getQuery(row);
            Document doc = new Document();
            doc.add(new Field(LUCENE_FIELD_QUERY, query,
                    Field.Store.YES, Field.Index.NOT_ANALYZED));
            long time = System.currentTimeMillis();
            doc.add(new Field(LUCENE_FIELD_MODIFIED,
                    DateTools.timeToString(time, DateTools.Resolution.SECOND),
                    Field.Store.YES, Field.Index.NOT_ANALYZED));
            StatementBuilder buff = new StatementBuilder();
            for (int index : indexColumns) {
                String columnName = columns[index];
                String data = asString(row[index], columnTypes[index]);
                // column names that start with _
                // must be escaped to avoid conflicts
                // with internal field names (_DATA, _QUERY, _modified)
                if (columnName.startsWith(LUCENE_FIELD_COLUMN_PREFIX)) {
                    columnName = LUCENE_FIELD_COLUMN_PREFIX + columnName;
                }
                doc.add(new Field(columnName, data,
                        Field.Store.NO, Field.Index.ANALYZED));
                buff.appendExceptFirst(" ");
                buff.append(data);
            }
            Field.Store storeText = STORE_DOCUMENT_TEXT_IN_INDEX ?
                    Field.Store.YES : Field.Store.NO;
            doc.add(new Field(LUCENE_FIELD_DATA, buff.toString(), storeText,
                    Field.Index.ANALYZED));
            try {
                indexAccess.writer.addDocument(doc);
                indexAccess.writer.commit();
                // recreate Searcher with the IndexWriter's reader.
View Full Code Here

          {
            // handle partial full pages
            break;
          }

          Document doc = hits.doc(i);

          // pull in our values
          String   nickname = doc.getField("nickname").stringValue();
          String   message = doc.getField("message").stringValue();
          String   channelname = doc.getField("channel").stringValue();
          String   botname = doc.getField("botname").stringValue();
          String   servername = doc.getField("servername").stringValue();
          Date   moment = DateField.stringToDate(doc.getField("moment").stringValue());
          String   day = mOutputDateFormat.format(moment);
          String   time = mOutputTimeFormat.format(moment);
          String   outputday = mDateFormat.format(moment);

          // stolen directly from ChannelLog
View Full Code Here

              {
                String       servername = resultSet.getString("servername").toLowerCase();
                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());
                }
View Full Code Here

  {
    String botname = bot.getName();
    String channelname = channel.getName().substring(1);
    String servername = channel.getServer().getServerName();

    Document doc = new Document();
    Calendar beginningOfDay = Calendar.getInstance();

    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;

    doc.add(new Field("moment", DateField.dateToString(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", channelname, true, true, true));
    doc.add(new Field("servername", servername, true, true, true));
    doc.add(new Field("nickname", message.getPrefix().getNickName(), true, true, true));
    doc.add(new Field("username", message.getPrefix().getUser(), true, true, true));
    doc.add(new Field("hostname", message.getPrefix().getHost(), true, true, true));
    doc.add(new Field("message", message.getTrailing(), true, true, true));

    addDocumentToQueue(getIndexName(botname, servername, channelname), doc);
  }
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 String getLines() {
        return headers.get("Lines", "");
    }

    public Document getOveriewDocument() {
        Document doc = new Document();
        doc.add( Field.Keyword("article.message-id", getMessageId()) );
        doc.add( Field.Text("article.subject", getSubject()) );
        doc.add( Field.Keyword("article.from", getFrom()) );
        try {
            doc.add( Field.Keyword("article.date", getDate()) );
        } catch( ParseException e ) {
        }
        doc.add( Field.Text("article.references", getReferences()) );
        doc.add( Field.UnIndexed("article.bytes", String.valueOf(getBody().length()) ) );
        doc.add( Field.UnIndexed("article.lines", getLines()) );
        doc.add( Field.UnIndexed("article.xref", getXRef()) );
        addNewsgroupArticleNumbers(doc);
        return doc;
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.document.Document

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.