Example usage for com.liferay.portal.kernel.search Field DESCRIPTION

List of usage examples for com.liferay.portal.kernel.search Field DESCRIPTION

Introduction

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

Prototype

String DESCRIPTION

To view the source code for com.liferay.portal.kernel.search Field DESCRIPTION.

Click Source Link

Usage

From source file:ca.efendi.datafeeds.search.CJProductIndexer.java

License:Apache License

@Override
protected Document doGetDocument(final CJProduct object) throws Exception {
    final Document document = getBaseModelDocument(CLASS_NAME, object);
    document.addText(Field.CAPTION, object.getName());
    document.addText(Field.CONTENT, HtmlUtil.extractText(object.getDescription()));
    document.addText(Field.DESCRIPTION, object.getDescription());
    document.addDate(Field.MODIFIED_DATE, object.getModifiedDate());
    //document.addText(Field.SUBTITLE, blogsEntry.getSubtitle());
    document.addText(Field.TITLE, object.getName());
    return document;
}

From source file:com.idetronic.eprint.service.impl.EprintLocalServiceImpl.java

License:Open Source License

public Hits getHits(String keyword, long companyId, long groupId) {
    // 1. Preparing a Search Context
    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    String[] CLASS_NAMES = { Eprint.class.getName() };
    searchContext.setEntryClassNames(CLASS_NAMES);
    long[] groupIds = { groupId };
    searchContext.setGroupIds(groupIds);
    // 2. Preparing a Query to search
    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
    String[] terms = { Field.DESCRIPTION, Field.TITLE };
    try {/*w ww .j ava2 s  .c o m*/
        searchQuery.addTerms(terms, keyword);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    // 3. Firing the query to get hits
    Hits hits = null;
    try {
        hits = SearchEngineUtil.search(searchContext, searchQuery);
    } catch (SearchException e) {
        e.printStackTrace();
    }
    return hits;
}

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

public Summary getSummary(Document document, String snippet, PortletURL portletURL) {

    String title = document.get(Field.TITLE);

    String content = snippet;//  w  w w . j ava 2  s .  c om

    if (Validator.isNull(snippet)) {
        content = document.get(Field.DESCRIPTION);

        if (Validator.isNull(content)) {
            content = StringUtil.shorten(document.get(Field.CONTENT), 200);
        }
    }

    String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("jspPage", "/admin/view_slogan.jsp");
    portletURL.setParameter("resourcePrimKey", resourcePrimKey);

    return new Summary(title, content, portletURL);

}

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {

    Slogan slogan = (Slogan) obj;/*w ww.ja v  a2  s  .  c om*/
    long companyId = slogan.getCompanyId();
    long groupId = getParentGroupId(slogan.getGroupId());
    long scopeGroupId = slogan.getGroupId();
    long userId = slogan.getUserId();
    long resourcePrimKey = slogan.getPrimaryKey();
    String title = slogan.getSloganText();
    String content = slogan.getSloganText();
    String description = slogan.getSloganText();
    Date modifiedDate = slogan.getSloganDate();

    long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(Slogan.class.getName(),
            resourcePrimKey);

    List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(Slogan.class.getName(),
            resourcePrimKey);

    String[] assetCategoryNames = StringUtil.split(ListUtil.toString(categories, "name"));

    // EE lets you do this quicker: 

    // String[] assetCategoryNames =
    //     AssetCategoryLocalServiceUtil.getCategoryNames(
    //         Slogan.class.getName(), resourcePrimKey);

    String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(Slogan.class.getName(), resourcePrimKey);

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, resourcePrimKey);

    document.addModifiedDate(modifiedDate);

    document.addKeyword(Field.COMPANY_ID, companyId);
    document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    document.addKeyword(Field.GROUP_ID, groupId);
    document.addKeyword(Field.SCOPE_GROUP_ID, scopeGroupId);
    document.addKeyword(Field.USER_ID, userId);
    document.addText(Field.TITLE, title);
    document.addText(Field.CONTENT, content);
    document.addText(Field.DESCRIPTION, description);
    document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);
    document.addKeyword("assetCategoryNames", assetCategoryNames);
    //document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);
    document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

    document.addKeyword(Field.ENTRY_CLASS_NAME, Slogan.class.getName());
    document.addKeyword(Field.ENTRY_CLASS_PK, resourcePrimKey);

    return document;
}

From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public List<LMSBook> AdvanceSearchAny(long companyId, long groupId, String title, String author, String desc) {

    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    searchContext.setEntryClassNames(CLASS_NAMES);
    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
    Hits hits = null;/*  w  w  w.j  av  a  2 s  .c o  m*/
    try {
        String[] terms = { Field.TITLE, Field.DESCRIPTION, Field.NAME };
        searchQuery.addTerms(terms, getModelClassName());
        searchQuery = createQuery(getModelClassName(), getModelClassName(), searchContext, searchQuery);
        hits = SearchEngineUtil.search(searchContext, searchQuery);
    } catch (SearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<LMSBook> books = null;

    if (hits != null && hits.getLength() > 0) {
        books = new ArrayList<LMSBook>();
        for (Document document : hits.getDocs()) {

            long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK));
            try {
                LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId);
                books.add(book);
            } catch (PortalException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return books;

}

From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public List<LMSBook> advanceSearchAll(long companyId, long groupId, String title, String author, String desc,
        String type) {// w  w w  .  jav a  2s  . co m

    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    searchContext.setEntryClassNames(CLASS_NAMES);

    BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);
    contextQuery.addRequiredTerm(Field.COMPANY_ID, companyId);
    contextQuery.addRequiredTerm(Field.PORTLET_ID,
            Long.toString(ClassNameLocalServiceUtil.getClassNameId(LMSBook.class)));

    BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
    fullQuery.setQueryConfig(searchContext.getQueryConfig());
    try {
        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
    Hits hits = null;

    if (Validator.isNotNull(title)) {
        Sort sort = new Sort(Field.TITLE, true);
        searchContext.setSorts(new Sort[] { sort });

        fullQuery = createQuery(Field.TITLE, title, searchContext, fullQuery);

    }
    if (Validator.isNotNull(author)) {
        fullQuery = createQuery(Field.NAME, author, searchContext, fullQuery);
    }
    if (Validator.isNotNull(desc)) {
        fullQuery = createQuery(Field.DESCRIPTION, desc, searchContext, fullQuery);
    }

    if (searchQuery.clauses().size() > 0) {
        try {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        hits = SearchEngineUtil.search(searchContext, fullQuery);
    } catch (SearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<LMSBook> books = new ArrayList<LMSBook>();

    if (hits != null && hits.getLength() > 0) {
        for (Document document : hits.getDocs()) {

            long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK));
            try {
                LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId);
                books.add(book);
            } catch (PortalException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return books;
}

From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public List<LMSBook> searchBooks(long companyId, String keywords) {

    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    searchContext.setEntryClassNames(CLASS_NAMES);

    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

    Hits hits = null;/*w ww.  j  a v  a 2 s .com*/

    try {
        String[] terms = { Field.TITLE, Field.DESCRIPTION };
        searchQuery.addTerms(terms, keywords);
        hits = SearchEngineUtil.search(searchContext, searchQuery);
    } catch (SearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<LMSBook> books = null;

    if (hits != null && hits.getLength() > 0) {
        books = new ArrayList<LMSBook>();
        for (Document document : hits.getDocs()) {

            long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK));
            try {
                LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId);
                books.add(book);
            } catch (PortalException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return books;

}

From source file:com.liferay.asset.categories.internal.search.AssetCategoryIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(AssetCategory assetCategory) throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing asset category " + assetCategory);
    }//from  ww w.  jav  a2 s  .  c  o m

    Document document = getBaseModelDocument(CLASS_NAME, assetCategory);

    document.addKeyword(Field.ASSET_CATEGORY_ID, assetCategory.getCategoryId());

    List<AssetCategory> categories = new ArrayList<>(1);

    categories.add(assetCategory);

    addSearchAssetCategoryTitles(document, Field.ASSET_CATEGORY_TITLE, categories);

    document.addKeyword(Field.ASSET_PARENT_CATEGORY_ID, assetCategory.getParentCategoryId());
    document.addKeyword(Field.ASSET_VOCABULARY_ID, assetCategory.getVocabularyId());

    Locale siteDefaultLocale = _portal.getSiteDefaultLocale(assetCategory.getGroupId());

    addLocalizedField(document, Field.DESCRIPTION, siteDefaultLocale, assetCategory.getDescriptionMap());

    document.addText(Field.NAME, assetCategory.getName());
    addLocalizedField(document, Field.TITLE, siteDefaultLocale, assetCategory.getTitleMap());
    document.addKeyword("leftCategoryId", assetCategory.getLeftCategoryId());

    if (_log.isDebugEnabled()) {
        _log.debug("Document " + assetCategory + " indexed successfully");
    }

    return document;
}

From source file:com.liferay.asset.categories.internal.search.AssetVocabularyIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(AssetVocabulary assetVocabulary) throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing asset vocabulary " + assetVocabulary);
    }//from w  w w .  j  a v  a  2  s .  c  o m

    Document document = getBaseModelDocument(CLASS_NAME, assetVocabulary);

    document.addKeyword(Field.ASSET_VOCABULARY_ID, assetVocabulary.getVocabularyId());

    Locale siteDefaultLocale = _portal.getSiteDefaultLocale(assetVocabulary.getGroupId());

    addLocalizedField(document, Field.DESCRIPTION, siteDefaultLocale, assetVocabulary.getDescriptionMap());

    document.addText(Field.NAME, assetVocabulary.getName());
    addLocalizedField(document, Field.TITLE, siteDefaultLocale, assetVocabulary.getTitleMap());

    if (_log.isDebugEnabled()) {
        _log.debug("Document " + assetVocabulary + " indexed successfully");
    }

    return document;
}

From source file:com.liferay.asset.internal.search.AssetEntryIndexer.java

License:Open Source License

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

    if (searchContext.getAttributes() == null) {
        return;// ww  w . j a v a 2  s.co  m
    }

    addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
    addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
    addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
}