Foros de discusión
Content Indexing : how to add new fields in the search index ? [SOLVED]
Lirone75 M., modificado hace 12 años.
Content Indexing : how to add new fields in the search index ? [SOLVED]
Regular Member Mensajes: 118 Fecha de incorporación: 19/03/07 Mensajes recientes
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.
Suresh Nimmakayala, modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Liferay Master Mensajes: 690 Fecha de incorporación: 18/08/04 Mensajes recientes
create a new index in database on journal articles if your field not existed
Thanks
Suresh
Thanks
Suresh
Lirone75 M., modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Regular Member Mensajes: 118 Fecha de incorporación: 19/03/07 Mensajes recientesSuresh 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.
Oliver Bayer, modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Liferay Master Mensajes: 894 Fecha de incorporación: 18/02/09 Mensajes recientes
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
Lirone75 M., modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Regular Member Mensajes: 118 Fecha de incorporación: 19/03/07 Mensajes recientesOliver 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 ?
Oliver Bayer, modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Liferay Master Mensajes: 894 Fecha de incorporación: 18/02/09 Mensajes recientes
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
Lirone75 M., modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Regular Member Mensajes: 118 Fecha de incorporación: 19/03/07 Mensajes recientesOliver 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;
}
}
Raghu teja, modificado hace 12 años.
RE: Content Indexing : how to add new fields in the search index ?
Junior Member Mensajes: 61 Fecha de incorporación: 10/03/11 Mensajes recientes
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