Package org.apache.lucene.document

Examples of org.apache.lucene.document.Document


    Thread.sleep(5000);
  }

  public void testFindLeadDocument() throws Exception{
    reloadIndexDB();
    Document d = manager.findLeadDocument(urlHash)
    assertNotNull(d)
    String v = d.get(DocumentCreator.FIELD_INDEX_TYPE);
    assertEquals(DocumentCreator.INDEX_TYPE_LEAD,v);
    String id = d.get(DocumentCreator.FIELD_BOOKMARK_ID);
    assertEquals("112",id);
    testDestroy();
  }
View Full Code Here


    testDestroy();
  }
 
  public void testFindNonLeadDocument() throws Exception{
    reloadIndexDB();
    Document d = manager.findNonLeadDocument(urlHash)
    assertNotNull(d)
    String v = d.get(DocumentCreator.FIELD_INDEX_TYPE);
    assertNull(v);
    String id = d.get(DocumentCreator.FIELD_BOOKMARK_ID);
    assertEquals("111",id);
    testDestroy();
  }
View Full Code Here

    reloadIndexDB();
    doc2.add(DocumentCreator.createFieldTitle("some title"));
    //doc2.add(new Field(DocumentCreator.FIELD_TITLE,"some title",Field.Store.YES,Field.Index.TOKENIZED));
    manager.updateIndex(doc2);
    Thread.sleep(5000);
    Document leadDoc = manager.findLeadDocument(urlHash);
    assertEquals(leadDoc.get(DocumentCreator.FIELD_TITLE),"some title");
    testDestroy();
  }
View Full Code Here

    reloadIndexDB();   
    manager.deleteIndex(doc2);
    Thread.sleep(5000);
    // after deleting the current lead doc, the non-lead doc will
    // be promoted to be the lead doc.
    Document leadDoc = manager.findLeadDocument(urlHash);
    assertEquals(leadDoc.get(DocumentCreator.FIELD_BOOKMARK_ID),"111");
    testDestroy();
  }
View Full Code Here

  }

  public void testAddIndex() throws Exception {
    reloadIndexDB();
    String doc3UrlHash = "999aaa2222";
    Document doc3 = new Document();
    doc3.add(DocumentCreator.createFieldUrlHash(doc3UrlHash));
    //doc3.add(new Field(DocumentCreator.FIELD_URL_MD5,doc3UrlHash,Field.Store.YES,Field.Index.UN_TOKENIZED));
    doc3.add(DocumentCreator.createFieldBookmarkId(2000));
    //doc3.add(new Field(DocumentCreator.FIELD_BOOKMARK_ID,"2000",Field.Store.YES,Field.Index.UN_TOKENIZED));
    manager.addIndex(doc3);
    Thread.sleep(5000);
    Document leadDoc1 = manager.findLeadDocument(urlHash);
    Document leadDoc2 = manager.findLeadDocument(doc3UrlHash);
    assertEquals("112",leadDoc1.get(DocumentCreator.FIELD_BOOKMARK_ID));
    assertEquals("2000",leadDoc2.get(DocumentCreator.FIELD_BOOKMARK_ID));
    testDestroy();
  }
View Full Code Here

      BoboIndexReader subReader = _subReaders[readerIndex];
      return subReader.document(docid - _starts[readerIndex]);
    }
    else
    {
      Document doc = super.document(docid);
      Collection<FacetHandler<?>> facetHandlers = _facetHandlerMap.values();
      for (FacetHandler<?> facetHandler : facetHandlers)
      {
        String[] vals = facetHandler.getFieldValues(this,docid);
        if (vals != null)
        {
          String[] values = doc.getValues(facetHandler.getName());
          Set<String> storedVals = new HashSet<String>(Arrays.asList(values));
         
          for (String val : vals)
          {
          storedVals.add(val);
          }
          doc.removeField(facetHandler.getName());
         
          for (String val : storedVals){
            doc.add(new Field(facetHandler.getName(),
                      val,
                      Field.Store.NO,
                      Field.Index.NOT_ANALYZED));
          }
        }
View Full Code Here

    bmark1.setCreatedOn(createdOn);
    bmark1.setLastUpdated(lastUpdated);
  }

  public void testCreateDocument() throws Exception {
    Document doc1 = DocumentCreator.createDocument(bmark1);
    assertNotNull(doc1);
   
    String id = doc1.get(DocumentCreator.FIELD_BOOKMARK_ID);
    assertEquals("101",id);

    String username = doc1.get(DocumentCreator.FIELD_USER);
    assertEquals("jsmith",username);
   
    String title = doc1.get(DocumentCreator.FIELD_TITLE);
    assertEquals("Title of a Bookmark",title);
 
    String link = doc1.get(DocumentCreator.FIELD_URL);
    assertEquals("http://example.org/foo1.html",link);
   
    String md5 = doc1.get(DocumentCreator.FIELD_URL_MD5);
    assertEquals("123456789abcdefg",md5);
   
    String[] tags = doc1.getValues(DocumentCreator.FIELD_TAG);
    assertEquals(4,tags.length);
    List<String> tagList = Arrays.asList(tags);
    assertTrue(tagList.contains("tag1"));
    assertTrue(tagList.contains("tag2"));
    assertTrue(tagList.contains("foo.bar"));
    assertTrue(tagList.contains("machine:tag=233"));
   
    String cDate = doc1.get(DocumentCreator.FIELD_CREATED_ON);
    String lDate = doc1.get(DocumentCreator.FIELD_LAST_UPDATED);
    assertEquals("20080123",cDate);
    assertEquals("20080211",lDate);
   
    String txt = doc1.get(DocumentCreator.FIELD_TEXT);
    assertNotNull(txt);
  }
View Full Code Here

    String txt = doc1.get(DocumentCreator.FIELD_TEXT);
    assertNotNull(txt);
  }

  public void testRemoveIndexTypeLead() throws Exception{
    Document doc1 = new Document();
    doc1.add(new Field(DocumentCreator.FIELD_BOOKMARK_ID,"100",Field.Store.YES,Field.Index.UN_TOKENIZED));
    doc1.add(new Field(DocumentCreator.FIELD_INDEX_TYPE,DocumentCreator.INDEX_TYPE_LEAD,Field.Store.NO,Field.Index.UN_TOKENIZED));
    doc1.add(new Field(DocumentCreator.FIELD_INDEX_TYPE,"other-type",Field.Store.NO,Field.Index.UN_TOKENIZED));
    doc1 = DocumentCreator.removeIndexTypeLead(doc1);
    Field[] fields = doc1.getFields(DocumentCreator.FIELD_INDEX_TYPE);
    assertEquals(1,fields.length);
    assertEquals("other-type",fields[0].stringValue());
    fields = doc1.getFields(DocumentCreator.FIELD_BOOKMARK_ID);
    assertEquals(1,fields.length)
  }
View Full Code Here

    fields = doc1.getFields(DocumentCreator.FIELD_BOOKMARK_ID);
    assertEquals(1,fields.length)
  }
 
  public void testAddIndexTypeLead() throws Exception {
    Document doc1 = new Document();
    doc1.add(new Field(DocumentCreator.FIELD_BOOKMARK_ID,"100",Field.Store.YES,Field.Index.UN_TOKENIZED));
    doc1 = DocumentCreator.addIndexTypeLead(doc1);
    Field[] fields = doc1.getFields(DocumentCreator.FIELD_INDEX_TYPE);
    assertEquals(1,fields.length);
    assertEquals(DocumentCreator.INDEX_TYPE_LEAD,fields[0].stringValue())
  }
View Full Code Here

 
  public static Document createDocument(Bookmark bookmark) {
    if (bookmark == null) {
      return null;
    }
    Document doc = new Document();
    if (bookmark.getId() <= 0) {
      logger.error("DocumentCreator detects an input Bookmark ID <= 0");
      return null;
    }
    doc.add(createFieldBookmarkId(bookmark.getId()));
   
    if (bookmark.getTitle() == null || bookmark.getTitle().length() == 0) {
      logger.error("DocumentCreator detects an input "
          + "Bookmark Title has length 0. BookmarkId="
          + bookmark.getId());
      return null;
    }
    doc.add(createFieldTitle(bookmark.getTitle()));
    doc.add(createFieldText(bookmark.getTitle()));

   
    // user:
    if (bookmark.getUser() == null
        || bookmark.getUser().getUsername() == null) {
      logger.error("DocumentCreator detects an input "
          + "Bookmark Username == null. BookmarkId="
          + bookmark.getId());
      return null;
    }
    doc.add(createFieldUser(bookmark.getUser().getUsername()));
   
    if (bookmark.getLink() == null || bookmark.getLink().getUrl() == null) {
      logger.error("DocumentCreator detects an input "
          + "Bookmark URL == null. BookmarkId=" + bookmark.getId());
      return null;
    }
    doc.add(createFieldUrl(bookmark.getLink().getUrl()));   
   
    // url: & urlMD5:
    if (bookmark.getLink() == null || bookmark.getLink().getUrlHash() == null) {
      logger.error("DocumentCreator detects an input "
          + "Bookmark URL Hash == null. BookmarkId=" + bookmark.getId());
      return null;
    }
    doc.add(createFieldUrlHash(bookmark.getLink().getUrlHash()));
   
    // notes:
    String notes = extractText(bookmark.getNotes());
    if (notes != null) {
      doc.add(createFieldNotes(bookmark.getNotes()));
      doc.add(createFieldText(bookmark.getNotes()));
    }
    // tag:
    List<String> tagList = bookmark.getTagList();
    for (String tag : tagList) {
      doc.add(createFieldTag(tag));
      doc.add(createFieldText(tag));
    }
    // createdOn:
    if (bookmark.getCreatedOn() == null) {
      logger.error("DocumentCreator detects an input "
          + "Bookmark createdOn == null. BookmarkId="
          + bookmark.getId());
      return null;
    }
    doc.add(createFieldCreatedOn(bookmark.getCreatedOn()));
   
    // lastUpdated:
    if (bookmark.getLastUpdated() == null) {
      logger.error("DocumentCreator detects an input "
          + "Bookmark lastUpdated == null. BookmarkId="
          + bookmark.getId());
      return null;
    }   
    doc.add(createFieldLastUpdated(bookmark.getLastUpdated()));   
    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.