protected void searchByKeywordsInsideParentBaseModel() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

    baseModel = addBaseModel(null, true, getSearchKeywords(), serviceContext);

    BaseModel<?> parentBaseModel1 = getParentBaseModel(group, serviceContext);

    searchContext.setFolderIds(new long[] {(Long) parentBaseModel1.getPrimaryKeyObj()});
    searchContext.setKeywords(getSearchKeywords());

    int initialBaseModelsSearchCount =
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext);

    baseModel = addBaseModel(parentBaseModel1, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    BaseModel<?> parentBaseModel2 = getParentBaseModel(parentBaseModel1, serviceContext);

    baseModel = addBaseModel(parentBaseModel2, true, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 2,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  @Test
  public void testSearchRange() throws Exception {
    BookmarksEntry entry = BookmarksTestUtil.addEntry(_group.getGroupId(), true);

    BookmarksTestUtil.addEntry(_group.getGroupId(), true);
    BookmarksTestUtil.addEntry(_group.getGroupId(), true);
    BookmarksTestUtil.addEntry(_group.getGroupId(), true);

    SearchContext searchContext =
        BookmarksTestUtil.getSearchContext(
            _group.getCompanyId(), _group.getGroupId(), entry.getFolderId(), "test");

    Indexer indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    searchContext.setEnd(3);
    searchContext.setFolderIds((long[]) null);
    searchContext.setStart(1);

    Hits hits = indexer.search(searchContext);

    Assert.assertEquals(4, hits.getLength());

    Document[] documents = hits.getDocs();

    Assert.assertEquals(2, documents.length);
  }
  protected void search(
      FileEntry fileEntry, boolean rootFolder, String keywords, boolean assertTrue)
      throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute("paginationType", "regular");
    searchContext.setCompanyId(fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] {fileEntry.getFolderId()});
    searchContext.setGroupIds(new long[] {fileEntry.getRepositoryId()});
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    searchContext.setQueryConfig(queryConfig);

    Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

    Hits hits = indexer.search(searchContext);

    List<Document> documents = hits.toList();

    boolean found = false;

    for (Document document : documents) {
      long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      if (fileEntryId == fileEntry.getFileEntryId()) {
        found = true;

        break;
      }
    }

    String message = "Search engine could not find ";

    if (rootFolder) {
      message += "root file entry by " + keywords;
    } else {
      message += "file entry by " + keywords;
    }

    message += " using query " + hits.getQuery();

    if (assertTrue) {
      Assert.assertTrue(message, found);
    } else {
      Assert.assertFalse(message, found);
    }
  }
  protected String buildFolderQuery(boolean searchSubfolders) throws Exception {

    SearchContext searchContext = getSearchContext();

    searchContext.setFolderIds(new long[] {_repository.getDlFolderId()});
    searchContext.setKeywords("test");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setAttribute("capabilityQuery", CapabilityQuery.BOTHCOMBINED.value());
    queryConfig.setSearchSubfolders(searchSubfolders);

    return _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);
  }
  protected void search(boolean rootFolder, String keywords) throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(_fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] {_fileEntry.getFolderId()});
    searchContext.setGroupIds(new long[] {_fileEntry.getRepositoryId()});
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    searchContext.setQueryConfig(queryConfig);

    Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntry.class);

    List<Document> documents = indexer.search(searchContext).toList();

    boolean found = false;

    for (Document document : documents) {
      long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      if (fileEntryId == _fileEntry.getFileEntryId()) {
        found = true;

        break;
      }
    }

    String message = "Search engine could not find ";

    if (rootFolder) {
      message += "root file entry by " + keywords;
    } else {
      message += "file entry by " + keywords;
    }

    assertTrue(message, found);
  }