掲示板
Content Indexing : how to add new fields in the search index ? [SOLVED]
12年前 に Lirone75 M. によって更新されました。
Content Indexing : how to add new fields in the search index ? [SOLVED]
Regular Member 投稿: 118 参加年月日: 07/03/19 最新の投稿
Hi,
I'd like to add the field displayDate of the journal articles in the search index ?
The final goal is to have seach results sorted by displayDate.
Can I add easily have this new field in the search index ?
I use the solr plugin, is solr the solution for this kind of requierement ?
Should I configure solr stuff (shema) to have automatically this new field in the index ?
Thank you for your response.
I'd like to add the field displayDate of the journal articles in the search index ?
The final goal is to have seach results sorted by displayDate.
Can I add easily have this new field in the search index ?
I use the solr plugin, is solr the solution for this kind of requierement ?
Should I configure solr stuff (shema) to have automatically this new field in the index ?
Thank you for your response.
12年前 に Suresh Nimmakayala によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Liferay Master 投稿: 690 参加年月日: 04/08/18 最新の投稿
create a new index in database on journal articles if your field not existed
Thanks
Suresh
Thanks
Suresh
12年前 に Lirone75 M. によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Regular Member 投稿: 118 参加年月日: 07/03/19 最新の投稿Suresh Nimmakayala:
create a new index in database on journal articles if your field not existed
Thanks
Suresh
My need is to execute lucene query (full text search) + using field "displayDate" to restrict and sort result. But the field "displayDate" is not indexed so I can consider it in the lucene query.
Could you explain why you talking about database ? I'm talking about search index used by sarch portlet that execute query on lucene index not database index.
12年前 に Oliver Bayer によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Liferay Master 投稿: 894 参加年月日: 09/02/18 最新の投稿
Hi,
take a look at the Indexer classes - in your case the "com.liferay.journal.util.Indexer" class. While indexing the reindex method is called. The indexed fields are set in the "getArticleDocument" method. See the following code snippet:
HTH Oli
take a look at the Indexer classes - in your case the "com.liferay.journal.util.Indexer" class. While indexing the reindex method is called. The indexed fields are set in the "getArticleDocument" method. See the following code snippet:
...
doc.addText(Field.TITLE, title);
...
doc.addText(Field.DESCRIPTION, description);
...
HTH Oli
12年前 に Lirone75 M. によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Regular Member 投稿: 118 参加年月日: 07/03/19 最新の投稿Oliver Bayer:
Hi,
take a look at the Indexer classes - in your case the "com.liferay.journal.util.Indexer" class. While indexing the reindex method is called. The indexed fields are set in the "getArticleDocument" method. See the following code snippet:... doc.addText(Field.TITLE, title); ... doc.addText(Field.DESCRIPTION, description); ...
HTH Oli
Ok I added my new field displayDate and I can order on it.
As I only want article that have an displayDate < current date, I'd like to add an numeric range term or a range term like this :
protected BooleanQuery createFullQuery(
BooleanQuery contextQuery, SearchContext searchContext) throws Exception{
BooleanQuery booleanQuery = super.createFullQuery(contextQuery, searchContext);
long now = Calendar.getInstance().getTime().getTime();
booleanQuery.addRangeTerm("displayDate", 0L, now);
return booleanQuery;
}
but it doesn't work. I take a look at the date format in the index and I found for display date this : 20110601195700 so yyyymm.... do you know the helper class that can help me to add the upper bound of my date range correctely ?
12年前 に Oliver Bayer によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Liferay Master 投稿: 894 参加年月日: 09/02/18 最新の投稿
Hi,
you can try using the methods of "DateUtil" to get a date in a given pattern (the same how you've indexed the journal article) e.g.:
HTH Oli
you can try using the methods of "DateUtil" to get a date in a given pattern (the same how you've indexed the journal article) e.g.:
DateUtil.getCurrentDate(String pattern, Locale locale);
HTH Oli
12年前 に Lirone75 M. によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Regular Member 投稿: 118 参加年月日: 07/03/19 最新の投稿Oliver Bayer:
Hi,
you can try using the methods of "DateUtil" to get a date in a given pattern (the same how you've indexed the journal article) e.g.:DateUtil.getCurrentDate(String pattern, Locale locale);
HTH Oli
No in fact, I found the internal lucene date format in class : com.liferay.portal.kernel.search.DocumentImpl :
private static final String _DATE_FORMAT_PATTERN = "yyyyMMddHHmmss";
Here is the complete code of the indexer wich deal with displayDate :
package mypackage.portlet.journal.util;
import java.util.Calendar;
import java.util.Date;
import com.liferay.portal.kernel.search.BooleanQuery;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
import com.liferay.portlet.journal.model.JournalArticle;
import com.liferay.portlet.journal.util.JournalIndexer;
public class MyJournalIndexer extends JournalIndexer {
private static final String _DATE_FORMAT_PATTERN = "yyyyMMddHHmmss";
/**
* add the displayDate field in the index for journal articles.
*/
protected Document doGetDocument(Object obj) throws Exception {
JournalArticle article = (JournalArticle)obj;
Document document = super.doGetDocument(article);
document.addDate("displayDate", article.getDisplayDate());
return document;
}
/**
* add the displayDate criteria to search only on journal article that have a display date > now.
*/
protected BooleanQuery createFullQuery(
BooleanQuery contextQuery, SearchContext searchContext) throws Exception{
BooleanQuery booleanQuery = super.createFullQuery(contextQuery, searchContext);
Date now = Calendar.getInstance().getTime();
String dateString = FastDateFormatFactoryUtil.getSimpleDateFormat(
_DATE_FORMAT_PATTERN).format(now);
booleanQuery.addNumericRangeTerm("displayDate", 0L, Long.valueOf(dateString).longValue());
return booleanQuery;
}
}
12年前 に Raghu teja によって更新されました。
RE: Content Indexing : how to add new fields in the search index ?
Junior Member 投稿: 61 参加年月日: 11/03/10 最新の投稿
hi Lirone,
I Couldn't find addNumericRangeTerm() in BooleanQuery in Liferay 6.0.5
I Couldn't find addNumericRangeTerm() in BooleanQuery in Liferay 6.0.5