留言板
Liferay 7 Indexing issue
Hi all,
I am creating one learning project in which I'm integrating indexing with Liferay 7 ce ga 4.
I found reference blog to create indexer in Liferay 7 which is:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-a-guestbook-indexer
I Followed all the steps but still I'm unable to create indexer.
Here, I pasted code which I did:
TestIndexer.java
I follow all the steps described in above linked document but still i'm getting this below error
Error: The type javax.portlet.PortletResponse cannot be resolved. It is indirectly referenced from required .class files
Can Any one help me to solve this issue?
I am creating one learning project in which I'm integrating indexing with Liferay 7 ce ga 4.
I found reference blog to create indexer in Liferay 7 which is:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-a-guestbook-indexer
I Followed all the steps but still I'm unable to create indexer.
Here, I pasted code which I did:
TestIndexer.java
package com.wp.test.search;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.search.IndexWriterHelper;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.util.GetterUtil;
import com.wp.test.model.Test;
import com.wp.test.service.TestLocalService;
import com.wp.test.service.permission.TestPermission;
import com.wp.test.util.CustomPortletKeys;
@Component(
immediate = true,
service = Test.class
)
public class TestIndexer extends com.liferay.portal.kernel.search.BaseIndexer<test> {
public static final String CLASS_NAME = Test.class.getName();
public TestIndexer() {
setDefaultSelectedFieldNames(
Field.ASSET_TAG_NAMES, Field.COMPANY_ID, Field.CONTENT,
Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);
setPermissionAware(true);
setFilterSearch(true);
}
@Override
public String getClassName() {
return CLASS_NAME;
}
@Override
public boolean hasPermission(
PermissionChecker permissionChecker, String entryClassName,
long entryClassPK, String actionId)
throws Exception {
return TestPermission.contains(permissionChecker, entryClassPK, ActionKeys.VIEW);
}
@Override
protected Document doGetDocument(Test test) throws Exception {
Document document = getBaseModelDocument(CLASS_NAME, test);
//document.addDate(Field.MODIFIED_DATE, );
//Locale defaultLocale =PortalUtil.getSiteDefaultLocale(test.getUserId());
//String localizedField = LocalizationUtil.getLocalizedName(Field.TITLE, defaultLocale.toString());
//document.addText(localizedField, test);
return document;
}
@Override
protected void doReindex(String className, long classPK) throws Exception {
Test test = _testLocalService.getTest(classPK);
doReindex(test);
}
@Override
protected void doReindex(String[] ids) throws Exception {
long companyId = GetterUtil.getLong(ids[0]);
reindexTests(companyId);
}
@Override
protected void doReindex(Test test) throws Exception {
Document document = getDocument(test);
indexWriterHelper.updateDocument(getSearchEngineId(), test.getCompanyId(), document,isCommitImmediately());
}
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
PortletResponse portletResponse) throws Exception {
Summary summary = createSummary(document);
summary.setMaxContentLength(200);
return summary;
}
protected void reindexTests(long companyId) throws PortalException {
final IndexableActionableDynamicQuery indexableActionableDynamicQuery = _testLocalService
.getIndexableActionableDynamicQuery();
indexableActionableDynamicQuery.setCompanyId(companyId);
indexableActionableDynamicQuery.setPerformActionMethod(
new ActionableDynamicQuery.PerformActionMethod<test>() {
@Override
public void performAction(Test test) {
try {
Document document = getDocument(test);
indexableActionableDynamicQuery.addDocuments(document);
} catch (PortalException pe) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to index test " + test.getTestId(), pe);
}
}
}
});
indexableActionableDynamicQuery.setSearchEngineId(getSearchEngineId());
indexableActionableDynamicQuery.performActions();
}
private static final Log _log = LogFactoryUtil.getLog(TestIndexer.class);
@Reference
protected IndexWriterHelper indexWriterHelper;
@Reference
private TestLocalService _testLocalService;
}
</test></test>
I follow all the steps described in above linked document but still i'm getting this below error
Error: The type javax.portlet.PortletResponse cannot be resolved. It is indirectly referenced from required .class files
Can Any one help me to solve this issue?
Hi Jiten,
That error normally means that there is a class that is required that is not on the classpath. Can you share with us what your bnd file looks like? .. Throw in your gradle file while you are at it.
That error normally means that there is a class that is required that is not on the classpath. Can you share with us what your bnd file looks like? .. Throw in your gradle file while you are at it.
Andrew Jardine:
Hi Jiten,
That error normally means that there is a class that is required that is not on the classpath. Can you share with us what your bnd file looks like? .. Throw in your gradle file while you are at it.
Thanks for the revert back. I have fixed the error for javax.portlet.PortletResponse . I added compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0" in gradle setting.
However, I'm getting new error for following.
[Class com.wp.test.search.TestIndexer is not assignable to specified service com.wp.test.model.Test]
Not sure, what still missing.
This is my BND file.
Bundle-Name: test-service
Bundle-SymbolicName: com.wp.test.service
Bundle-Version: 1.0.0
Liferay-Require-SchemaVersion: 1.0.0
Liferay-Service: true
Export-Package: com.wp.test.search.service.permission,\
com.wp.test.search
This is my Gradle File
dependencies {
compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
compileOnly project(":modules:test:test-api")
}
buildService {
apiDir = "../test-api/src/main/java"
}
group = "com.wp.test"
Can you show me the BND for your test-api module? That is the one that is most important in this case because you need to make sure that the packages that contain the classes you want to reference (in your test-service) are actually exposed. Remember that the proper implementation is that your "users" of the service will actually reference the API and allow the OSGI to inject the impl at runtime.
Hello Andrew,
Following is BND file for test-api.
I think, com.we.test.model is exported in api.
Other thing, I noticed in journal article's code, its referencing Indexer.class as service, where as in the user class, its mentioned to use custom entity for the same. Is that something, that needs to be looked on? ref: JournalArticleIndexer
Following is BND file for test-api.
Bundle-Name: test-api
Bundle-SymbolicName: com.wp.test.api
Bundle-Version: 1.0.0
Export-Package:\
com.wp.test.exception,\
com.wp.test.model,\
com.wp.test.service,\
com.wp.test.service.persistence
-includeresource: META-INF/service.xml=../test-service/service.xml
I think, com.we.test.model is exported in api.
Other thing, I noticed in journal article's code, its referencing Indexer.class as service, where as in the user class, its mentioned to use custom entity for the same. Is that something, that needs to be looked on? ref: JournalArticleIndexer
I think you want to follow the method that is used for the JournalArticle. I am trying to dig up something from the last time I did this and I think it is on another machine that is not accessible to me right now. If my memory serves me correctly though, I use the Indexer.class service for my custom implementation.
.. you can always check to see if your Indexer is registered by using the IndexerRegistryUtil to get the list of registers and then check to make sure that yours is in it.
.. you can always check to see if your Indexer is registered by using the IndexerRegistryUtil to get the list of registers and then check to make sure that yours is in it.
Thanks for answer.
I solved this problem. Now I have new problem.
Indexer works fine. I used "Elasticsearch" google chrome extension to find indexed data. I got indexed document in that.
When i try to get indexed document using "Hits" in searching portlet I don't get data.
my code is:
Indexer Class :
I got this output server log:
Some buddy please help me out
I solved this problem. Now I have new problem.
Indexer works fine. I used "Elasticsearch" google chrome extension to find indexed data. I got indexed document in that.
When i try to get indexed document using "Hits" in searching portlet I don't get data.
my code is:
public void keywordSearch(RenderRequest renderRequest, RenderResponse renderResponse){
try {
HttpServletRequest request = PortalUtil.getHttpServletRequest(renderRequest);
SearchContext searchContext = SearchContextFactory.getInstance(request);
searchContext.setKeywords("test");
searchContext.setAttribute("paginationType", "more");
searchContext.setStart(0);
searchContext.setEnd(10);
Indexer indexer = IndexerRegistryUtil.getIndexer(Test.class);
System.out.println("Indexer Name ::"+indexer);
Hits hits = indexer.search(searchContext);
System.out.println("hits.length :::"+hits.getLength());
System.out.println("hits :::"+hits);
} catch (Exception e) {
e.printStackTrace();
}
}
Indexer Class :
package com.liferay.docs.guestbook.search;
import java.util.Locale;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.liferay.docs.guestbook.model.Test;
import com.liferay.docs.guestbook.service.TestLocalService;
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.search.BaseIndexer;
import com.liferay.portal.kernel.search.BooleanQuery;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.search.IndexWriterHelper;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.search.Summary;
import com.liferay.portal.kernel.search.filter.BooleanFilter;
import com.liferay.portal.kernel.util.GetterUtil;
@Component(immediate = true, service = Indexer.class)
public class TestDemoIndexer extends BaseIndexer<test>{
public static final String CLASS_NAME = Test.class.getName();
public TestDemoIndexer(){
setDefaultSelectedFieldNames(
Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK,
Field.UID, Field.SCOPE_GROUP_ID, Field.GROUP_ID,"pec");
setDefaultSelectedLocalizedFieldNames(Field.TITLE, Field.CONTENT);
setFilterSearch(true);
setPermissionAware(true);
}
@Override
public String getClassName() {
return CLASS_NAME;
}
@Override
public void postProcessContextBooleanFilter(
BooleanFilter contextBooleanFilter, SearchContext searchContext)
throws Exception {
addStatus(contextBooleanFilter, searchContext);
}
@Override
public void postProcessSearchQuery(
BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
SearchContext searchContext)
throws Exception {
System.out.println("===>> Test.postProcessSearchQuery()<<========");
System.out.println("b4 localised call --- searchQuery.toString() ::: " + searchQuery.toString());
addSearchLocalizedTerm(searchQuery, searchContext, Field.TITLE, false);
addSearchLocalizedTerm(searchQuery, searchContext, Field.CONTENT, false);
System.out.println("after localised call --- searchQuery.toString() ::: " + searchQuery.toString());
}
@Override
protected void doDelete(Test test) throws Exception {
deleteDocument(test.getCompanyId(), test.getTestId());
}
@Override
protected Document doGetDocument(Test test) throws Exception {
Document document = getBaseModelDocument(CLASS_NAME, test);
document.addDate(Field.MODIFIED_DATE, test.getModifiedDate());
document.addDate(Field.CREATE_DATE, test.getCreateDate());
document.addText("pec", test.getPEC());
document.addText(Field.TITLE, "Amit_PEC");
return document;
}
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
PortletResponse portletResponse) throws Exception {
Summary summary = createSummary(document);
summary.setMaxContentLength(200);
return summary;
}
@Override
protected void doReindex(Test test) throws Exception {
Document document = getDocument(test);
indexWriterHelper.updateDocument(
getSearchEngineId(), test.getCompanyId(), document,
isCommitImmediately());
}
@Override
protected void doReindex(String className, long classPK) throws Exception {
Test test= _testLocalService.getTest(classPK);
doReindex(test);
}
@Override
protected void doReindex(String[] ids) throws Exception {
long companyId = GetterUtil.getLong(ids[0]);
reindexTests(companyId);
}
protected void reindexTests(long companyId)
throws PortalException {
final IndexableActionableDynamicQuery indexableActionableDynamicQuery =
_testLocalService.getIndexableActionableDynamicQuery();
indexableActionableDynamicQuery.setCompanyId(companyId);
indexableActionableDynamicQuery.setPerformActionMethod(
new ActionableDynamicQuery.PerformActionMethod<test>() {
@Override
public void performAction(Test test) {
try {
Document document = getDocument(test);
indexableActionableDynamicQuery.addDocuments(document);
}
catch (PortalException pe) {
if (_log.isWarnEnabled()) {
_log.warn(
"Unable to index test " + test.getTestId(),
pe);
}
}
}
});
indexableActionableDynamicQuery.setSearchEngineId(getSearchEngineId());
indexableActionableDynamicQuery.performActions();
}
private static final Log _log = LogFactoryUtil.getLog(TestDemoIndexer.class);
@Reference
protected IndexWriterHelper indexWriterHelper;
@Reference
private TestLocalService _testLocalService;
}
</test></test>
I got this output server log:
Indexer Name ::com.liferay.docs.guestbook.search.TestDemoIndexer@c866d396
hits.length :::0
hits :::{docs={}, length=0, query={booleanClauses=[{MUST({booleanClauses=[{SHOULD({booleanClauses=[{SHOULD({className=WildcardQueryImpl, queryTerm={field=assetCategoryTitles, value=*test*}})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{SHOULD({className=WildcardQueryImpl, queryTerm={field=assetCategoryTitles_en_US, value=*test*}})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{SHOULD({className=WildcardQueryImpl, queryTerm={field=assetCategoryTitles, value=*test*}})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{SHOULD({className=WildcardQueryImpl, queryTerm={field=assetTagNames, value=*test*}})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=comments, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=comments, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=comments, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=description, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=description, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=50, type=PHRASE, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=description, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=properties, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=properties, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=properties, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=url, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=url, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=url, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{SHOULD({className=WildcardQueryImpl, queryTerm={field=userName, value=*test*}})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=guestbookName, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=guestbookName, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=guestbookName, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=guestbookName_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=guestbookName_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=guestbookName_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=title_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=content_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=pec, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=pec, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=pec, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}, {SHOULD({booleanClauses=[{MUST({booleanClauses=[{SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=pec_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=null, value=test})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=pec_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE_PREFIX, value=test})}], className=BooleanQueryImpl})}, {SHOULD({analyzer=null, className=MatchQuery, cutOffFrequency=null, field=pec_en_US, fuzziness=null, fuzzyTranspositions=null, lenient=null, maxExpansions=null, minShouldMatch=null, operator=null, prefixLength=null, slop=null, type=PHRASE, value=test})}], className=BooleanQueryImpl})}], className=BooleanQueryImpl})}], className=BooleanQueryImpl}]
Some buddy please help me out
Andrew Jardine,修改在6 年前。
RE: Liferay 7 Indexing issue (答复)
Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
When I have these kids of problems I usually go back to basics and try using a different branch of the API to see if I am able to retrieve my data using a simpler query. Try using something like this to see if you can get your records --
Set a break point and check out the hits results. Start with that and see if you get something back. If you do then you know that the culprit must be the indexer logic that is constructing the query -- perhaps it is adding something as required that needs to be optional. I'll tell you this, with the current query that you cut and paste? no way I am going to read that first
// get your kywords
String keywords = ParamUtil...
// get your search context as you have already
searchContext.setKeywords(keywords);
// build a basic query
BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
searchQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, Test.class.getName());
// run it
Hits hits = IndexSearcherHelperUtil.search(searchContext, searchQuery);
Set a break point and check out the hits results. Start with that and see if you get something back. If you do then you know that the culprit must be the indexer logic that is constructing the query -- perhaps it is adding something as required that needs to be optional. I'll tell you this, with the current query that you cut and paste? no way I am going to read that first
Hello All,
I am working with Liferay 7 CE GA 6. I want to add a search functionality with custom entity. I have created an Indexer with help of following :
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-a-guestbook-indexer
I followed all the steps from that doc but I am unable to find the records using "Hits". It's size returns 0.
Following is my code:
EmployeeIndexer.java :
view_search.jsp :
build.gradle of employee-service :
bnd.bnd of employee-service :
However, I am not getting any exception in the log.
Thanks for your help in advance.
I am working with Liferay 7 CE GA 6. I want to add a search functionality with custom entity. I have created an Indexer with help of following :
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-a-guestbook-indexer
I followed all the steps from that doc but I am unable to find the records using "Hits". It's size returns 0.
Following is my code:
EmployeeIndexer.java :
package com.lr.test.employee.search;
import java.util.Locale;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.search.BaseIndexer;
import com.liferay.portal.kernel.search.BooleanQuery;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.search.IndexWriterHelper;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.search.Summary;
import com.liferay.portal.kernel.search.filter.BooleanFilter;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.util.GetterUtil;
import com.lr.test.employee.model.Employee;
import com.lr.test.employee.service.EmployeeLocalService;
@Component(
immediate = true,
service = Indexer.class
)
public class EmployeeIndexer extends BaseIndexer<employee> {
public static final String CLASS_NAME = Employee.class.getName();
public EmployeeIndexer() {
setDefaultSelectedFieldNames(
Field.ASSET_TAG_NAMES, Field.COMPANY_ID, Field.CONTENT,
Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);
setFilterSearch(true);
setPermissionAware(true);
}
@Override
public String getClassName() {
return CLASS_NAME;
}
@Override
public boolean hasPermission(PermissionChecker permissionChecker, String entryClassName,
long entryClassPK, String actionId) throws Exception {
return true;
}
@Override
public void postProcessContextBooleanFilter(
BooleanFilter contextBooleanFilter, SearchContext searchContext)
throws Exception {
addStatus(contextBooleanFilter, searchContext);
}
@Override
public boolean isVisible(long classPK, int status) throws Exception {
return true;
}
@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
SearchContext searchContext) throws Exception {
addSearchLocalizedTerm(searchQuery, searchContext, Field.TITLE, true);
addSearchLocalizedTerm(searchQuery, searchContext, Field.CONTENT, true);
addSearchLocalizedTerm(searchQuery, searchContext, "empcode", true);
addSearchLocalizedTerm(searchQuery, searchContext, "empname", true);
addSearchLocalizedTerm(searchQuery, searchContext, "department", true);
}
@Override
protected void doDelete(Employee employee) throws Exception {
deleteDocument(employee.getCompanyId(), employee.getPrimaryKey());
}
@Override
protected Document doGetDocument(Employee employee) throws Exception {
Document document = getBaseModelDocument(CLASS_NAME, employee);
document.addKeyword(Field.COMPANY_ID, employee.getCompanyId());
document.addNumber("empcode", employee.getEmpcode());
document.addText("empname", employee.getEmpname());
document.addText("department", employee.getDepartment());
return document;
}
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet,
PortletRequest portletRequest, PortletResponse portletResponse) {
Summary summary = createSummary(document);
summary.setMaxContentLength(200);
return summary;
}
@Override
protected void doReindex(Employee employee) throws Exception {
Document document = getDocument(employee);
indexWriterHelper.updateDocument(
getSearchEngineId(), employee.getCompanyId(), document, isCommitImmediately());
}
@Override
protected void doReindex(String className, long classPK) throws Exception {
Employee employee = _employeeLocalService.getEmployee(classPK);
doReindex(employee);
}
@Override
protected void doReindex(String[] ids) throws Exception {
long companyId = GetterUtil.getLong(ids[0]);
reindexEmployee(companyId);
}
protected void reindexEmployee(long companyId) throws PortalException {
final IndexableActionableDynamicQuery indexableActionableDynamicQuery =
_employeeLocalService.getIndexableActionableDynamicQuery();
indexableActionableDynamicQuery.setCompanyId(companyId);
indexableActionableDynamicQuery.setPerformActionMethod(
new ActionableDynamicQuery.PerformActionMethod<employee>() {
@Override
public void performAction(Employee employee) {
try {
Document document = getDocument(employee);
indexableActionableDynamicQuery.addDocuments(document);
} catch (PortalException pe) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to index guestbook " +
employee.getEmployeeid(), pe);
}
}
}
});
indexableActionableDynamicQuery.setSearchEngineId(getSearchEngineId());
indexableActionableDynamicQuery.performActions();
}
private static final Log _log = LogFactoryUtil.getLog(EmployeeIndexer.class);
@Reference
protected IndexWriterHelper indexWriterHelper;
@Reference
private EmployeeLocalService _employeeLocalService;
}</employee></employee>
view_search.jsp :
<%
String keywords = ParamUtil.getString(request, "keywords");
%>
<liferay-portlet:renderurl varimpl="searchURL">
<portlet:param name="mvcPath" value="/employeeweb/view_search.jsp" />
</liferay-portlet:renderurl>
<aui:form action="<%= searchURL %>" method="get" name="searchForm">
<liferay-portlet:renderurlparams varImpl="searchURL" />
<liferay-ui:header backURL="<%= backURL.toString() %>" title="caption.search" />
<div class="search-form">
<span class="aui-search-bar">
<aui:input type="text" inlineField="<%= true %>" label="" name="keywords" size="30" title="search-entries" />
<aui:button type="submit" value="btn.search" />
</span>
</div>
</aui:form>
<%
SearchContext searchContext = SearchContextFactory.getInstance(request);
searchContext.setKeywords(keywords);
searchContext.setAttribute("paginationType", "more");
searchContext.setStart(0);
searchContext.setEnd(10);
Indexer indexer = IndexerRegistryUtil.getIndexer(Employee.class);
Hits hits = indexer.search(searchContext);
List<employee> employeeList = new ArrayList<employee>();
for (int i = 0; i < hits.getDocs().length; i++) {
Document doc = hits.doc(i);
long employeeid = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
Employee employee = null;
try {
employee = EmployeeLocalServiceUtil.getEmployee(employeeid);
} catch (PortalException pe) {
pe.printStackTrace();
} catch (SystemException se) {
se.printStackTrace();
}
employeeList.add(Employee);
}
%>
<liferay-ui:search-container delta="20" emptyresultsmessage="no records found" total="<%= employeeList.size() %>">
<liferay-ui:search-container-results results="<%= employeeList %>" />
<liferay-ui:search-container-row classname="Employee" keyproperty="employeeid" modelvar="employee" escapedmodel="<%=true%>">
<liferay-ui:search-container-column-text name="Emp Code" property="empcode" />
<liferay-ui:search-container-column-text name="Emp Name" property="empname" />
<liferay-ui:search-container-column-text name="Department" property="department" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />
</liferay-ui:search-container>
</employee></employee>
build.gradle of employee-service :
dependencies {
compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"
compileOnly group: "com.liferay", name: "com.liferay.registry.api", version: "1.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly project(":modules:employee:employee-api")
}
buildService {
apiDir = "../employee-api/src/main/java"
}
group = "com.lr.test.employee"
bnd.bnd of employee-service :
Bundle-Name: employee-service
Bundle-SymbolicName: com.lr.test.employee.service
Bundle-Version: 1.0.0
Liferay-Require-SchemaVersion: 1.0.0
Liferay-Service: true
Export-Package:\
com.lr.test.employee.search
However, I am not getting any exception in the log.
Thanks for your help in advance.
Hi Anna,
The first thing I would suggest doing is querying your elasticesearch directly to make sure that the records are in fact in there. I use postman to do this,but there are many options out there, including browser based plugins.
Can you try that first to make sure there is actual data to retrieve?
The first thing I would suggest doing is querying your elasticesearch directly to make sure that the records are in fact in there. I use postman to do this,but there are many options out there, including browser based plugins.
Can you try that first to make sure there is actual data to retrieve?
Andrew Jardine:
Hi Anna,
The first thing I would suggest doing is querying your elasticesearch directly to make sure that the records are in fact in there. I use postman to do this,but there are many options out there, including browser based plugins.
Can you try that first to make sure there is actual data to retrieve?
Hello Andrew,
Thanks for the reply.
Yes, there are actual data to retrieve and I tried with your suggestion. But I am not getting any records.