Package org.apache.lucene.document

Examples of org.apache.lucene.document.Document


   * @return a Lucene document of the representative bookmark
   */
  public Document findLeadDocument(String urlHash) {
    IndexReader reader = null;
    TermDocs termDocs = null;
    Document leadDoc = null;
    try {
      boolean exists = IndexReader.indexExists(indexDirectory);
      if (exists == true) {
        reader = IndexReader.open(indexDirectory);
        Term key = new Term(DocumentCreator.FIELD_URL_MD5, urlHash);
        termDocs = reader.termDocs(key);
        boolean found = false;
        while (termDocs.next() && found == false) {
          int pos = termDocs.doc();
          // use FieldSelector for more efficient loading of Fields.
          // load only what's needed to determine a leading document
          Document d = reader.document(pos, new FieldSelector() {
            private static final long serialVersionUID = 1426724242925499003L;

            public FieldSelectorResult accept(String field) {
              if (field.equals(DocumentCreator.FIELD_INDEX_TYPE)) {
                return FieldSelectorResult.LOAD_AND_BREAK;
              } else {
                return FieldSelectorResult.NO_LOAD;
              }
            }
          });
          String[] values = d
              .getValues(DocumentCreator.FIELD_INDEX_TYPE);
          if (values != null) {
            List<String> vList = Arrays.asList(values);
            if (vList.contains(DocumentCreator.INDEX_TYPE_LEAD) == true) {
              leadDoc = reader.document(pos);
View Full Code Here


   * @return a Lucene document of a non-representative bookmark
   */
  public Document findNonLeadDocument(String urlHash) {
    IndexReader reader = null;
    TermDocs termDocs = null;
    Document leadDoc = null;
    try {
      boolean exists = IndexReader.indexExists(indexDirectory);
      if (exists == true) {
        reader = IndexReader.open(indexDirectory);
        Term key = new Term(DocumentCreator.FIELD_URL_MD5, urlHash);
        termDocs = reader.termDocs(key);
        boolean found = false;
        while (termDocs.next() && found == false) {
          int pos = termDocs.doc();
          // use FieldSelector for more efficient loading of Fields.
          // load only what's needed to determine a leading document
          Document d = reader.document(pos, new FieldSelector() {
            private static final long serialVersionUID = 1426724242925499003L;

            public FieldSelectorResult accept(String field) {
              if (field.equals(DocumentCreator.FIELD_INDEX_TYPE)) {
                return FieldSelectorResult.LOAD_AND_BREAK;
              } else {
                return FieldSelectorResult.NO_LOAD;
              }
            }

          });
          String[] values = d
              .getValues(DocumentCreator.FIELD_INDEX_TYPE);
          if (values != null) {
            List<String> vList = Arrays.asList(values);
            if (vList.contains(DocumentCreator.INDEX_TYPE_LEAD) == false) {
              leadDoc = reader.document(pos);
View Full Code Here

  @Override
  public Document doc(int docid) throws CorruptIndexException,
      IOException
  {
    Document doc = super.doc(docid);
    for (FacetHandler<?> handler : _runtimeFacetHandlerMap.values())
    {
      String[] vals = handler.getFieldValues(_reader,docid);
      for (String val : vals)
      {
        doc.add(new Field(handler.getName(),
                          val,
                          Field.Store.NO,
                          Field.Index.NOT_ANALYZED));
      }
    }
View Full Code Here

    else
    {
      logger.warn("facet handler: " + fieldname
          + " not defined, looking at stored field.");
      // this is not predefined, so it will be slow
      Document doc = _reader.document(docid, new FieldSelector()
      {
        private static final long serialVersionUID = 1L;

        public FieldSelectorResult accept(String field)
        {
          if (fieldname.equals(field))
          {
            return FieldSelectorResult.LOAD_AND_BREAK;
          }
          else
          {
            return FieldSelectorResult.NO_LOAD;
          }
        }
      });
      return doc.getValues(fieldname);
    }
  }
View Full Code Here

  }

  private void doIndex(List<Bookmark> bookmarks){
    try{
      for(Bookmark b : bookmarks){
        Document d = DocumentCreator.createDocument(b);
        if(d != null){
          searchIndexManager.addIndex(d);
        }
      }     
    }catch(Exception e){
View Full Code Here

          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);
View Full Code Here


  //*-- create the Lucene Index
  public void loadIndex(IndexWriter ramIW, boolean storeTermVector) throws IOException
  {
   Document doc = new Document();
   doc.add( new Field("key", getFileName(), Field.Store.YES, Field.Index.NO) );
   doc.add(new Field("contents", getContents().toString(), Field.Store.NO, Field.Index.TOKENIZED) );
   doc.add( new Field("type", getFileType(), Field.Store.YES, Field.Index.NO) );
   doc.add( new Field("category", getTextType(), Field.Store.YES, Field.Index.NO) );
   ramIW.addDocument(doc);
  }
View Full Code Here

  }

  //*-- create the Lucene Index
  public void loadIndex(IndexWriter ramIW, boolean storeTermVector) throws IOException
  {
   Document doc = new Document();
   doc.add( new Field("key", getFileName(), Field.Store.YES, Field.Index.NO) );
   doc.add(new Field("contents", getContents().toString(), Field.Store.NO, Field.Index.TOKENIZED) );
   doc.add( new Field("type", getFileType(), Field.Store.YES, Field.Index.NO) );
   doc.add( new Field("category", getTextType(), Field.Store.YES, Field.Index.NO) );
   ramIW.addDocument(doc);
  }
View Full Code Here

   }

  //*-- create the Lucene Index
  public void loadIndex(IndexWriter ramIW, boolean storeTermVector) throws IOException
  {
   Document doc = new Document();
   doc.add( new Field("key", getFileName(), Field.Store.YES, Field.Index.NO) );
   doc.add(new Field("contents", getContents().toString(), Field.Store.NO, Field.Index.TOKENIZED) );
   doc.add( new Field("type", getFileType(), Field.Store.YES, Field.Index.NO) );
   doc.add( new Field("category", getTextType(), Field.Store.YES, Field.Index.NO) );
   ramIW.addDocument(doc);
  }
View Full Code Here

}

//*-- create the Lucene Index
public void loadIndex(IndexWriter ramIW, boolean storeTermVector) throws IOException
{
  Document doc = new Document();
  doc.add( new Field("key", getFileName(), Field.Store.YES, Field.Index.NO) );
  doc.add(new Field("contents", getContents().toString(), Field.Store.NO, Field.Index.TOKENIZED) );
  doc.add( new Field("type", getFileType(), Field.Store.YES, Field.Index.NO) );
  ramIW.addDocument(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.