@Override
  public Hits search(SearchContext searchContext) throws SearchException {
    searchContext.setSearchEngineId(SearchEngineHelper.GENERIC_ENGINE_ID);

    BooleanQuery fullQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    return search(searchContext, fullQuery);
  }
  @Test
  public void testWildcardQuery() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("test*.jpg");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals("(cmis:name LIKE 'test%.jpg' OR cmis:createdBy LIKE 'test%.jpg')", cmisQuery);
  }
  @Test
  public void testProximityQuery() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("\"test document\"~10");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals(
        "(cmis:name = 'test document' OR cmis:createdBy = 'test " + "document')", cmisQuery);
  }
  @Test
  public void testPhraseQuery() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("\"My test document.jpg\"");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals(
        "(cmis:name = 'My test document.jpg' OR cmis:createdBy = 'My " + "test document.jpg')",
        cmisQuery);
  }
  @Test
  public void testRangeQuery() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("createDate:[20091011000000 TO 20091110235959]");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals(
        "cmis:creationDate >= 2009-10-11T00:00:00.000Z AND "
            + "cmis:creationDate <= 2009-11-10T23:59:59.000Z",
        cmisQuery);
  }
  @Test
  public void testBooleanQuery() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("+test* -test.doc");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals(
        "((cmis:name LIKE 'test%' AND NOT(cmis:name = 'test.doc')) OR "
            + "(cmis:createdBy LIKE 'test%' AND NOT(cmis:createdBy = "
            + "'test.doc')))",
        cmisQuery);
  }
  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);
  }
  @Test
  public void testContainsOnlySupportedWithApostrophe() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("test's");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setAttribute("capabilityQuery", CapabilityQuery.FULLTEXTONLY.value());

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals("CONTAINS('test\\'s')", cmisQuery);
  }
  @Test
  public void testContainsCombinedSupportedQuery() throws Exception {
    SearchContext searchContext = getSearchContext();

    searchContext.setKeywords("test");

    BooleanQuery searchQuery = RepositorySearchQueryBuilderUtil.getFullQuery(searchContext);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    String cmisQuery = _cmisSearchQueryBuilder.buildQuery(searchContext, searchQuery);

    assertQueryEquals(
        "((cmis:name = 'test' OR cmis:createdBy = 'test') OR " + "CONTAINS('test'))", cmisQuery);
  }