フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Lirone75 M.
Content Indexing : how to add new fields in the search index ? [SOLVED]
2011/06/17 13:05
答え

Lirone75 M.

ランク: Regular Member

投稿: 235

参加年月日: 2007/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.
Suresh Nimmakayala
RE: Content Indexing : how to add new fields in the search index ?
2011/06/16 12:55
答え

Suresh Nimmakayala

ランク: Liferay Master

投稿: 645

参加年月日: 2004/08/17

最近の投稿

create a new index in database on journal articles if your field not existed

Thanks
Suresh
Lirone75 M.
RE: Content Indexing : how to add new fields in the search index ?
2011/06/16 23:19
答え

Lirone75 M.

ランク: Regular Member

投稿: 235

参加年月日: 2007/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.
Oliver Bayer
RE: Content Indexing : how to add new fields in the search index ?
2011/06/17 0:58
答え

Oliver Bayer

ランク: Liferay Master

投稿: 889

参加年月日: 2009/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:

1...
2doc.addText(Field.TITLE, title);
3...
4doc.addText(Field.DESCRIPTION, description);
5...

HTH Oli
Lirone75 M.
RE: Content Indexing : how to add new fields in the search index ?
2011/06/17 3:46
答え

Lirone75 M.

ランク: Regular Member

投稿: 235

参加年月日: 2007/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:

1...
2doc.addText(Field.TITLE, title);
3...
4doc.addText(Field.DESCRIPTION, description);
5...

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 :


1    protected BooleanQuery createFullQuery(
2            BooleanQuery contextQuery, SearchContext searchContext) throws Exception{
3        BooleanQuery booleanQuery = super.createFullQuery(contextQuery, searchContext);
4        long now = Calendar.getInstance().getTime().getTime();
5        booleanQuery.addRangeTerm("displayDate", 0L, now);
6        return booleanQuery;
7    }

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
RE: Content Indexing : how to add new fields in the search index ?
2011/06/17 4:01
答え

Oliver Bayer

ランク: Liferay Master

投稿: 889

参加年月日: 2009/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.:

1DateUtil.getCurrentDate(String pattern, Locale locale);

HTH Oli
Lirone75 M.
RE: Content Indexing : how to add new fields in the search index ?
2011/06/17 6:42
答え

Lirone75 M.

ランク: Regular Member

投稿: 235

参加年月日: 2007/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.:

1DateUtil.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 :

1    private static final String _DATE_FORMAT_PATTERN = "yyyyMMddHHmmss";



Here is the complete code of the indexer wich deal with displayDate :

 1package mypackage.portlet.journal.util;
 2
 3import java.util.Calendar;
 4import java.util.Date;
 5
 6import com.liferay.portal.kernel.search.BooleanQuery;
 7import com.liferay.portal.kernel.search.Document;
 8import com.liferay.portal.kernel.search.SearchContext;
 9import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
10import com.liferay.portlet.journal.model.JournalArticle;
11import com.liferay.portlet.journal.util.JournalIndexer;
12
13public class MyJournalIndexer extends JournalIndexer {
14    private static final String _DATE_FORMAT_PATTERN = "yyyyMMddHHmmss";
15   
16    /**
17     * add the displayDate field in the index for journal articles.
18     */
19    protected Document doGetDocument(Object obj) throws Exception {
20        JournalArticle article = (JournalArticle)obj;
21        Document document = super.doGetDocument(article);
22        document.addDate("displayDate", article.getDisplayDate());
23        return document;
24    }
25   
26    /**
27     * add the displayDate criteria to search only on journal article that have a display date > now.
28     */
29    protected BooleanQuery createFullQuery(
30            BooleanQuery contextQuery, SearchContext searchContext) throws Exception{
31        BooleanQuery booleanQuery = super.createFullQuery(contextQuery, searchContext);
32        Date now = Calendar.getInstance().getTime();
33        String dateString = FastDateFormatFactoryUtil.getSimpleDateFormat(
34                _DATE_FORMAT_PATTERN).format(now);
35       
36        booleanQuery.addNumericRangeTerm("displayDate", 0L, Long.valueOf(dateString).longValue());
37       
38        return booleanQuery;
39    }
40   
41}
Raghu teja
RE: Content Indexing : how to add new fields in the search index ?
2012/01/30 22:27
答え

Raghu teja

ランク: Junior Member

投稿: 47

参加年月日: 2011/03/10

最近の投稿

hi Lirone,

I Couldn't find addNumericRangeTerm() in BooleanQuery in Liferay 6.0.5