Example usage for com.liferay.portal.kernel.search SearchContext getKeywords

List of usage examples for com.liferay.portal.kernel.search SearchContext getKeywords

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search SearchContext getKeywords.

Prototype

public String getKeywords() 

Source Link

Usage

From source file:com.liferay.document.library.repository.search.internal.RepositorySearchQueryBuilderImpl.java

License:Open Source License

protected void addSearchKeywords(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
        return;//from ww w. ja v  a  2 s.  c o m
    }

    BooleanQuery titleQuery = new BooleanQueryImpl();

    _repositorySearchQueryTermBuilder.addTerm(titleQuery, searchContext, Field.TITLE, keywords);

    if (titleQuery.hasClauses() && !contains(searchQuery, titleQuery)) {
        searchQuery.add(titleQuery, BooleanClauseOccur.SHOULD);
    }

    BooleanQuery userNameQuery = new BooleanQueryImpl();

    _repositorySearchQueryTermBuilder.addTerm(userNameQuery, searchContext, Field.USER_NAME, keywords);

    if (userNameQuery.hasClauses() && !contains(searchQuery, userNameQuery)) {

        searchQuery.add(userNameQuery, BooleanClauseOccur.SHOULD);
    }

    BooleanQuery contentQuery = new BooleanQueryImpl();

    _repositorySearchQueryTermBuilder.addTerm(contentQuery, searchContext, Field.CONTENT, keywords);

    if (contentQuery.hasClauses() && !contains(searchQuery, contentQuery)) {
        searchQuery.add(contentQuery, BooleanClauseOccur.SHOULD);
    }
}

From source file:com.liferay.google.drive.repository.GoogleDriveRepository.java

License:Open Source License

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

    try {/*from   w  w w  .  j a va  2  s .co m*/
        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<ExtRepositorySearchResult<?>>(
                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>(
                        googleDriveFolder, 1.0f, StringPool.BLANK);

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

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

                extRepositorySearchResults.add(extRepositorySearchResult);
            }
        }

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

        throw new SystemException(ioe);
    }
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

@Override
protected Map<String, Query> addSearchLocalizedTerm(BooleanQuery searchQuery, SearchContext searchContext,
        String field, boolean like) throws Exception {

    if (Validator.isNull(field)) {
        return Collections.emptyMap();
    }/* w w  w.  java2 s.c  o  m*/

    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;
}

From source file:com.liferay.knowledgebase.admin.util.AdminIndexer.java

License:Open Source License

@Override
public Hits search(SearchContext searchContext) throws SearchException {
    Hits hits = super.search(searchContext);

    String[] queryTerms = hits.getQueryTerms();

    String keywords = searchContext.getKeywords();

    queryTerms = ArrayUtil.append(queryTerms, KnowledgeBaseUtil.splitKeywords(keywords));

    hits.setQueryTerms(queryTerms);//ww  w  .  j  a v a 2  s. c  o m

    return hits;
}

From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

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

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

    if (tikaRawMetadataStructure != null) {
        addSearchDDMStruture(searchQuery, searchContext, tikaRawMetadataStructure);
    }/*from   w ww.  ja va 2  s  .c o m*/

    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);
        }
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
protected void addSearchLocalizedTerm(BooleanQuery searchQuery, SearchContext searchContext, String field,
        boolean like) throws Exception {

    if (Validator.isNull(field)) {
        return;/* w  ww  .  jav a  2s  .  c  o  m*/
    }

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

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

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

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

    if (Validator.isNull(searchContext.getKeywords())) {
        BooleanQuery localizedQuery = BooleanQueryFactoryUtil.create(searchContext);

        localizedQuery.addTerm(field, value, like);
        localizedQuery.addTerm(localizedField, value, like);

        BooleanClauseOccur booleanClauseOccur = BooleanClauseOccur.SHOULD;

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

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

From source file:com.liferay.so.hook.indexer.UserIndexerPostProcessor.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNotNull(keywords)) {
        searchQuery.addTerm("projectTitles", keywords, true);
    }//from w w w . j a va2  s.c om
}

From source file:com.liferay.wiki.search.WikiPageTitleSearcher.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
        SearchContext searchContext) throws Exception {

    MatchQuery matchQuery = new MatchQuery(Field.TITLE, StringUtil.toLowerCase(searchContext.getKeywords()));

    matchQuery.setType(MatchQuery.Type.PHRASE_PREFIX);

    searchQuery.add(matchQuery, BooleanClauseOccur.MUST);
}

From source file:com.rivetlogic.portal.search.elasticsearch.util.ElasticsearchHelper.java

License:Open Source License

/**
 * Gets the search hits.//from w  w  w  .  ja  v a 2  s  . c om
 *
 * @param searchContext the search context
 * @param query the query
 * @return the search hits
 */
public Hits getSearchHits(SearchContext searchContext, Query query) {
    if (_log.isInfoEnabled()) {
        _log.info("Search against Elasticsearch with SearchContext");
    }
    Hits hits = new HitsImpl();
    hits.setStart(new Date().getTime());

    Client client = this._esConnector.getClient();

    String keywords = searchContext.getKeywords();
    SearchRequestBuilder searchRequestBuilder = client
            .prepareSearch(ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX)
            .setQuery(_esQueryBuilder.doSearch(query));

    // Handle Search Facet queries
    handleFacetQueries(searchContext, searchRequestBuilder);
    SearchResponse response = null;
    if (getSort(searchContext.getSorts()) != null) {
        searchRequestBuilder = searchRequestBuilder.setFrom(searchContext.getStart())
                .setSize(searchContext.getEnd()).addSort(getSort(searchContext.getSorts()));
    } else {
        searchRequestBuilder = searchRequestBuilder.setFrom(searchContext.getStart())
                .setSize(searchContext.getEnd());
    }
    response = searchRequestBuilder.execute().actionGet();
    collectFacetResults(searchContext, response);

    SearchHits searchHits = response.getHits();
    hits.setDocs(getDocuments(searchHits, searchContext));
    hits.setScores(getScores(searchHits));
    hits.setSearchTime((float) (System.currentTimeMillis() - hits.getStart()) / Time.SECOND);
    hits.setQuery(query);
    if (keywords != null) {
        hits.setQueryTerms(keywords.split(StringPool.SPACE));
    }
    hits.setLength((int) searchHits.getTotalHits());
    hits.setStart(hits.getStart());

    return hits;
}

From source file:org.xmlportletfactory.olafk.customer.util.CustomerIndexer.java

License:Open Source License

@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception {

    searchQuery.addTerm("name", searchContext.getKeywords());
    searchQuery.addTerm("street", searchContext.getKeywords());
    searchQuery.addTerm("city", searchContext.getKeywords());
    searchQuery.addTerm("zip", searchContext.getKeywords());

    super.postProcessSearchQuery(searchQuery, searchContext);
}