@Test
  public void testLocalizedSearch() throws Exception {
    SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId());

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

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

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

    Map<Locale, String> keywordsMap = new HashMap<Locale, String>();

    keywordsMap.put(LocaleUtil.getDefault(), "entity title");
    keywordsMap.put(LocaleUtil.HUNGARY, "entitas neve");

    baseModel = addBaseModelWithWorkflow(parentBaseModel, true, keywordsMap, serviceContext);

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

    searchContext.setAttribute(Field.TITLE, "nev");
    searchContext.setKeywords("nev");
    searchContext.setLocale(LocaleUtil.HUNGARY);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
      if (folderIds[0] == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return;
      }

      BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long folderId : folderIds) {
        try {
          BookmarksFolderServiceUtil.getFolder(folderId);
        } catch (Exception e) {
          continue;
        }

        folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
      }

      contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }
  }
  @Override
  protected void addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return;
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return;
    }

    field = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    if (searchContext.isAndSearch()) {
      searchQuery.addRequiredTerm(field, value, like);
    } else {
      searchQuery.addTerm(field, value, like);
    }
  }
  @Override
  public void deleteEntityDocuments(
      String searchEngineId, long companyId, String className, boolean commitImmediately)
      throws SearchException {

    if (isIndexReadOnly()) {
      return;
    }

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    if (searchEngine == null) {
      return;
    }

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    SearchContext searchContext = new SearchContext();

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

    setCommitImmediately(searchContext, commitImmediately);

    indexWriter.deleteEntityDocuments(searchContext, className);
  }
  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));
  }
  protected void searchComments() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

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

    searchContext.setIncludeDiscussions(true);

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

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

    baseModel = addBaseModel(parentBaseModel, true, RandomTestUtil.randomString(), serviceContext);

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

    addComment(baseModel, getSearchKeywords(), serviceContext);

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

    moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj());

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  protected void searchBaseModelWithUpdate() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

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

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

    searchContext.setKeywords(getSearchKeywords());

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

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

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

    String updatedKeywords = RandomTestUtil.randomString();

    baseModel = updateBaseModel(baseModel, updatedKeywords, serviceContext);

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

    searchContext.setKeywords(updatedKeywords);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  protected void searchByDDMStructureField() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

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

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

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

    baseModel = addBaseModelWithDDMStructure(parentBaseModel, getSearchKeywords(), serviceContext);

    searchContext.setAttribute("ddmStructureFieldName", getDDMStructureFieldName());
    searchContext.setAttribute("ddmStructureFieldValue", getSearchKeywords());

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

    updateDDMStructure(serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount,
        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);
  }
  @Override
  public void updateDocument(
      String searchEngineId, long companyId, Document document, boolean commitImmediately)
      throws SearchException {

    if (isIndexReadOnly() || (document == null)) {
      return;
    }

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

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    _searchPermissionChecker.addPermissionFields(companyId, document);

    SearchContext searchContext = new SearchContext();

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

    setCommitImmediately(searchContext, commitImmediately || ProxyModeThreadLocal.isForceSync());

    indexWriter.updateDocument(searchContext, document);
  }
  @Override
  public void addDocuments(
      String searchEngineId,
      long companyId,
      Collection<Document> documents,
      boolean commitImmediately)
      throws SearchException {

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

    SearchEngine searchEngine = _searchEngineHelper.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);

    setCommitImmediately(searchContext, commitImmediately);

    indexWriter.addDocuments(searchContext, documents);
  }
  protected SearchContext getSearchContext() {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(SearchEngineUtil.GENERIC_ENGINE_ID);

    return searchContext;
  }
  protected void searchComments() throws Exception {
    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setScopeGroupId(group.getGroupId());

    SearchContext searchContext = ServiceTestUtil.getSearchContext();

    searchContext.setIncludeDiscussions(true);

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

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

    baseModel = addBaseModel(parentBaseModel, true, serviceContext);

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

    addComment(baseModel, getSearchKeywords(), serviceContext);

    Assert.assertEquals(
        initialBaseModelsSearchCount + 2,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  @Override
  public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
      throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
      addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
      addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
      addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
    }

    addSearchTerm(searchQuery, searchContext, "ddmContent", false);
    addSearchTerm(searchQuery, searchContext, "extension", false);
    addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false);
    addSearchTerm(searchQuery, searchContext, "path", false);

    LinkedHashMap<String, Object> params =
        (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
      String expandoAttributes = (String) params.get("expandoAttributes");

      if (Validator.isNotNull(expandoAttributes)) {
        addSearchExpando(searchQuery, searchContext, expandoAttributes);
      }
    }
  }
  public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException {

    SearchContainer<MBMessage> searchContainer =
        new SearchContainer(
            _liferayPortletRequest, _liferayPortletResponse.createRenderURL(), null, null);

    SearchContext searchContext =
        SearchContextFactory.getInstance(_liferayPortletRequest.getHttpServletRequest());

    searchContext.setAttribute(
        Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class));

    searchContext.setAttribute("discussion", true);

    List<MBMessage> mbMessages = new ArrayList<>();

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

    Hits hits = indexer.search(searchContext);

    for (Document document : hits.getDocs()) {
      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK);

      mbMessages.add(mbMessage);
    }

    searchContainer.setResults(mbMessages);

    searchContainer.setTotal(hits.getLength());

    return searchContainer;
  }
  protected void searchVersions() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

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

    searchContext.setKeywords(getSearchKeywords());

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

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

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

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

    baseModel = updateBaseModel(baseModel, "liferay", serviceContext);

    Assert.assertEquals(
        initialBaseModelsCount,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));

    baseModel = updateBaseModel(baseModel, "portal", serviceContext);

    searchContext.setKeywords("portal");

    Assert.assertEquals(
        initialBaseModelsCount + 1,
        searchBaseModelsCount(getBaseModelClass(), group.getGroupId(), searchContext));
  }
  protected void setCommitImmediately(SearchContext searchContext, boolean commitImmediately) {

    if (!commitImmediately) {
      searchContext.setCommitImmediately(_commitImmediately);
    } else {
      searchContext.setCommitImmediately(true);
    }
  }
  @Override
  protected BooleanClause doGetFacetClause() {
    SearchContext searchContext = getSearchContext();

    FacetConfiguration facetConfiguration = getFacetConfiguration();

    JSONObject dataJSONObject = facetConfiguration.getData();

    String[] values = null;

    if (isStatic() && dataJSONObject.has("values")) {
      JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values");

      values = new String[valuesJSONArray.length()];

      for (int i = 0; i < valuesJSONArray.length(); i++) {
        values[i] = valuesJSONArray.getString(i);
      }
    }

    String[] valuesParam =
        StringUtil.split(GetterUtil.getString(searchContext.getAttribute(getFieldName())));

    if (!isStatic() && (valuesParam != null) && (valuesParam.length > 0)) {
      values = valuesParam;
    }

    if ((values == null) || (values.length == 0)) {
      return null;
    }

    BooleanQuery facetQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (String value : values) {
      FacetValueValidator facetValueValidator = getFacetValueValidator();

      if ((searchContext.getUserId() > 0) && !facetValueValidator.check(searchContext, value)) {

        continue;
      }

      TermQuery termQuery = TermQueryFactoryUtil.create(searchContext, getFieldName(), value);

      try {
        facetQuery.add(termQuery, BooleanClauseOccur.SHOULD);
      } catch (ParseException pe) {
        _log.error(pe, pe);
      }
    }

    if (!facetQuery.hasClauses()) {
      return null;
    }

    return BooleanClauseFactoryUtil.create(
        searchContext, facetQuery, BooleanClauseOccur.MUST.getName());
  }
  @Override
  public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
      throws Exception {

    Set<DDMStructure> ddmStructuresSet = new TreeSet<DDMStructure>();

    long[] groupIds = searchContext.getGroupIds();

    if ((groupIds != null) && (groupIds.length > 0)) {
      List<DLFileEntryType> dlFileEntryTypes =
          DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(groupIds);

      for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
        ddmStructuresSet.addAll(dlFileEntryType.getDDMStructures());
      }
    }

    Group group = GroupLocalServiceUtil.getCompanyGroup(searchContext.getCompanyId());

    DDMStructure tikaRawMetadataStructure =
        DDMStructureLocalServiceUtil.fetchStructure(
            group.getGroupId(),
            PortalUtil.getClassNameId(RawMetadataProcessor.class),
            "TikaRawMetadata");

    if (tikaRawMetadataStructure != null) {
      ddmStructuresSet.add(tikaRawMetadataStructure);
    }

    for (DDMStructure ddmStructure : ddmStructuresSet) {
      addSearchDDMStruture(searchQuery, searchContext, ddmStructure);
    }

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
      addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
      addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
      addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
    }

    addSearchTerm(searchQuery, searchContext, "extension", false);
    addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false);
    addSearchTerm(searchQuery, searchContext, "path", false);

    LinkedHashMap<String, Object> params =
        (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
      String expandoAttributes = (String) params.get("expandoAttributes");

      if (Validator.isNotNull(expandoAttributes)) {
        addSearchExpando(searchQuery, searchContext, expandoAttributes);
      }
    }
  }
  protected SearchContext buildSearchContext(
      long companyId,
      long[] groupIds,
      String title,
      long[] parentCategoryIds,
      long[] vocabularyIds,
      int start,
      int end,
      Sort sort) {

    SearchContext searchContext = new SearchContext();

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ASSET_PARENT_CATEGORY_IDS, parentCategoryIds);
    attributes.put(Field.ASSET_VOCABULARY_IDS, vocabularyIds);
    attributes.put(Field.TITLE, title);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setGroupIds(groupIds);
    searchContext.setKeywords(title);
    searchContext.setSorts(sort);
    searchContext.setStart(start);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    return searchContext;
  }
  @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 testMatchNotOnlyCompanyIdButAlsoQueryTerms() throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(TestPropsValues.getCompanyId());

    BooleanQuery query = new BooleanQueryImpl();

    query.addTerm("title", RandomTestUtil.randomString());

    assertEquals(0, query, searchContext);
  }
  @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);
  }
  @Override
  public void commit(String searchEngineId, long companyId) throws SearchException {

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    SearchContext searchContext = new SearchContext();

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

    indexWriter.commit(searchContext);
  }
  @Override
  public List<ExtRepositorySearchResult<?>> search(
      SearchContext searchContext, Query query, ExtRepositoryQueryMapper extRepositoryQueryMapper)
      throws PortalException {

    try {
      Drive drive = getDrive();

      Drive.Files driveFiles = drive.files();

      Drive.Files.List driveFilesList = driveFiles.list();

      String searchQuery =
          getSearchQuery(
              searchContext.getKeywords(), searchContext.getFolderIds(), extRepositoryQueryMapper);

      driveFilesList.setQ(searchQuery);

      FileList fileList = driveFilesList.execute();

      List<File> files = fileList.getItems();

      List<ExtRepositorySearchResult<?>> extRepositorySearchResults = new ArrayList<>(files.size());

      for (File file : files) {
        if (_FOLDER_MIME_TYPE.equals(file.getMimeType())) {
          GoogleDriveFolder googleDriveFolder = new GoogleDriveFolder(file, getRootFolderKey());

          ExtRepositorySearchResult<GoogleDriveFolder> extRepositorySearchResult =
              new ExtRepositorySearchResult<>(googleDriveFolder, 1.0f, StringPool.BLANK);

          extRepositorySearchResults.add(extRepositorySearchResult);
        } else {
          GoogleDriveFileEntry googleDriveFileEntry = new GoogleDriveFileEntry(file);

          ExtRepositorySearchResult<GoogleDriveFileEntry> extRepositorySearchResult =
              new ExtRepositorySearchResult<>(googleDriveFileEntry, 1.0f, StringPool.BLANK);

          extRepositorySearchResults.add(extRepositorySearchResult);
        }
      }

      return extRepositorySearchResults;
    } catch (IOException ioe) {
      _log.error(ioe, ioe);

      throw new SystemException(ioe);
    }
  }
  @Override
  protected Map<String, Query> addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return Collections.emptyMap();
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return Collections.emptyMap();
    }

    String localizedField = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    Map<String, Query> queries = new HashMap<>();

    if (Validator.isNull(searchContext.getKeywords())) {
      BooleanQuery localizedQuery = new BooleanQueryImpl();

      Query query = localizedQuery.addTerm(field, value, like);

      queries.put(field, query);

      Query localizedFieldQuery = localizedQuery.addTerm(localizedField, value, like);

      queries.put(field, localizedFieldQuery);

      BooleanClauseOccur booleanClauseOccur = BooleanClauseOccur.SHOULD;

      if (searchContext.isAndSearch()) {
        booleanClauseOccur = BooleanClauseOccur.MUST;
      }

      searchQuery.add(localizedQuery, booleanClauseOccur);
    } else {
      Query query = searchQuery.addTerm(localizedField, value, like);

      queries.put(field, query);
    }

    return queries;
  }
  @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);
  }
  @Override
  public void indexSpellCheckerDictionaries(String searchEngineId, long companyId)
      throws SearchException {

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    SearchContext searchContext = new SearchContext();

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

    indexWriter.indexSpellCheckerDictionaries(searchContext);
  }
  @Override
  public void indexQuerySuggestionDictionary(String searchEngineId, long companyId, Locale locale)
      throws SearchException {

    SearchEngine searchEngine = _searchEngineHelper.getSearchEngine(searchEngineId);

    IndexWriter indexWriter = searchEngine.getIndexWriter();

    SearchContext searchContext = new SearchContext();

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

    indexWriter.indexQuerySuggestionDictionary(searchContext);
  }