home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lucene example source code file (SingleDocSource.java)

This example Lucene source code file (SingleDocSource.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lucene tags/keywords

contentsource, doc_text, docdata, io, ioexception, ioexception, nomoredataexception, nomoredataexception, override, override, singledocsource, so, so, string, well

The Lucene SingleDocSource.java source code

package org.apache.lucene.benchmark.byTask.feeds;

import java.io.IOException;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Creates the same document each time {@link #getNextDocData(DocData)} is called.
 */
public class SingleDocSource extends ContentSource {
  
  private int docID = 0;

  static final String DOC_TEXT =  
    "Well, this is just some plain text we use for creating the " +
    "test documents. It used to be a text from an online collection " +
    "devoted to first aid, but if there was there an (online) lawyers " +
    "first aid collection with legal advices, \"it\" might have quite " +
    "probably advised one not to include \"it\"'s text or the text of " +
    "any other online collection in one's code, unless one has money " +
    "that one don't need and one is happy to donate for lawyers " +
    "charity. Anyhow at some point, rechecking the usage of this text, " +
    "it became uncertain that this text is free to use, because " +
    "the web site in the disclaimer of he eBook containing that text " +
    "was not responding anymore, and at the same time, in projGut, " +
    "searching for first aid no longer found that eBook as well. " +
    "So here we are, with a perhaps much less interesting " +
    "text for the test, but oh much much safer. ";
  
  // return a new docid
  private synchronized int newdocid() throws NoMoreDataException {
    if (docID > 0 && !forever) {
      throw new NoMoreDataException();
    }
    return docID++;
  }

  @Override
  public void close() throws IOException {}
  
  @Override
  public DocData getNextDocData(DocData docData) throws NoMoreDataException {
    int id = newdocid();
    addBytes(DOC_TEXT.length());
    docData.clear();
    docData.setName("doc" + id);
    docData.setBody(DOC_TEXT);
    return docData;
  }

  @Override
  public synchronized void resetInputs() throws IOException {
    super.resetInputs();
    docID = 0;
  }

}

Other Lucene examples (source code examples)

Here is a short list of links related to this Lucene SingleDocSource.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.