Beispiel #1
0
  /**
   * The solo purpose of this testing is to the ensure the basic functions (insert and remove) of a
   * document function properly.
   */
  @Test
  public void BasicFuntionTest() throws InterruptedException {
    Document doc =
        new Document("samplefiles", new CopyOnWriteArrayList<String>(), "1000samplefiles1000", 0);
    assertEquals("samplefiles", doc.getName());

    // Check insert function.
    doc.insertChar(0, "60");
    Thread.sleep(25);
    assertEquals("60a", doc.toString());

    doc.insertChar(0, "100");
    Thread.sleep(25);
    assertEquals("100a60a", doc.toString());

    // Check remove function.
    doc.removeChar(1);
    Thread.sleep(25);
    assertEquals("60a", doc.toString());

    // Check series of commands.
    doc.insertChar(1, "10");
    doc.insertChar(2, "20");
    doc.insertChar(3, "30");
    doc.insertChar(4, "40");
    doc.removeChar(3); // when we remove on the server we automatically remove 1 less
    doc.insertChar(4, "50");
    Thread.sleep(50);
    assertEquals("60a10a30a40a50a", doc.toString());
  }
  public static void addDocuments(
      String searchEngineId, long companyId, Collection<Document> documents)
      throws SearchException {

    if (isIndexReadOnly() || (documents == null) || documents.isEmpty()) {
      return;
    }

    SearchEngine searchEngine = getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    for (Document document : documents) {
      if (_log.isDebugEnabled()) {
        _log.debug("Add document " + document.toString());
      }

      _searchPermissionChecker.addPermissionFields(companyId, document);
    }

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setSearchEngineId(searchEngineId);

    indexWriter.addDocuments(searchContext, documents);
  }
Beispiel #3
0
  public String toString() {
    /* s is the string representation of the SpellChecker */
    String s = "Current State of SpellChecker:";
    s += "\n\tDictionary: ";
    if (dictionary == null) {
      s += "Not Loaded";
    } else {
      s += "\n\t\t" + dictionary.toString().replace("\n", "\n\t\t");
    }

    s += "\n\tDocument: ";
    if (document == null) {
      s += "Not Loaded";
    } else {
      s += "\n\t\t" + document.toString().replace("\n", "\n\t\t");
    }

    return s;
  }
Beispiel #4
0
  @Test
  public void appendMustCorrectlyMoveChildrenInsideOneParentElement() {
    Document doc = new Document("");
    Element body = doc.appendElement("body");
    body.appendElement("div1");
    body.appendElement("div2");
    final Element div3 = body.appendElement("div3");
    div3.text("Check");
    final Element div4 = body.appendElement("div4");

    ArrayList<Element> toMove = new ArrayList<Element>();
    toMove.add(div3);
    toMove.add(div4);

    body.insertChildren(0, toMove);

    String result = doc.toString().replaceAll("\\s+", "");
    assertEquals("<body><div3>Check</div3><div4></div4><div1></div1><div2></div2></body>", result);
  }
  public static void updateDocument(String searchEngineId, long companyId, Document document)
      throws SearchException {

    if (isIndexReadOnly()) {
      return;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Document " + document.toString());
    }

    SearchEngine searchEngine = getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    _searchPermissionChecker.addPermissionFields(companyId, document);

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setSearchEngineId(searchEngineId);

    indexWriter.updateDocument(searchContext, document);
  }
 @Test
 public void toStringNotNull() {
   Document model = new Document();
   assertNotNull(model.toString());
 }