Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Vitaliy Koshelenko
Search JournalArticles by field in content
24 ottobre 2012 13.47
Risposta

Vitaliy Koshelenko

Punteggio: Expert

Messaggi: 271

Data di Iscrizione: 25 marzo 2011

Messaggi recenti

Hi, everybody.

I need to search WebContent by specified field within it's content.
I have the WebContent Structure with a set of required fields. For example, I need to find all the articles with the value of "company" field - "Test Company".
The content of article is stored as xml:

1<root default-locale="en_US">
2   .....
3    <dynamic-element instance-id="R1qoQLxW" name="company" type="text">
4        <dynamic-content><![CDATA[Test Company]]></dynamic-content>
5    </dynamic-element>
6    .....
7</root>


So, the only way I have found for this search is like:

1String companyName = "Test Company";
2ClassLoader cl = PortalClassLoaderUtil.getClassLoader();
3DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(JournalArticle.class, cl)
4            .add(PropertyFactoryUtil.forName("structureId").eq("COMPANY_STRUCTURE"))
5            .add(PropertyFactoryUtil.forName("content").like("%<dynamic-content><![CDATA[" + companyName + "]]></dynamic-content>%"));
6journalArticles = JournalArticleLocalServiceUtil.dynamicQuery(dynamicQuery);


Does anybody know some other solution for this kind of search?
Please, help


Vitaliy
Hitoshi Ozawa
RE: Search JournalArticles by field in content
24 ottobre 2012 14.37
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7952

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

Instead of querying lportal database, it maybe better to update <indexer-class>com.liferay.portlet.journal.util.JournalIndexer</indexer-class> (liferay-portlet.xml) and search usinf Solr (I prefer to use Solr instead on default lucene).
Vitaliy Koshelenko
RE: Search JournalArticles by field in content
29 ottobre 2012 3.10
Risposta

Vitaliy Koshelenko

Punteggio: Expert

Messaggi: 271

Data di Iscrizione: 25 marzo 2011

Messaggi recenti

Hi, Histoshi.

Thanks for your reply.
But why does not Liferay provide special API for searching WebContent by fields of it's WebContentStructure?

Regards, Vitaliy
Hitoshi Ozawa
RE: Search JournalArticles by field in content
26 ottobre 2012 16.50
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7952

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

Search functionality is one of the weak point in liferay. You can create a post in Suggestions and Recommendations forum and create an improvement request in liferay jira.
Mikko Torri
RE: Search JournalArticles by field in content
1 marzo 2013 3.00
Risposta

Mikko Torri

Punteggio: Junior Member

Messaggi: 33

Data di Iscrizione: 9 maggio 2011

Messaggi recenti

Sorry if this comes in late, but you can search web contents content with very simple search query:
web_content/fieldname:searchterm

So in your case it would be
web_content/company:"Test Company"

No need to write Dynamic querries or use SOLR for something Lucene can do.
Vitaliy Koshelenko
RE: Search JournalArticles by field in content
11 marzo 2013 13.13
Risposta

Vitaliy Koshelenko

Punteggio: Expert

Messaggi: 271

Data di Iscrizione: 25 marzo 2011

Messaggi recenti

Hi, Mikko!

Thanks for your reply. But where should I place this query ? Can you write, plase, the complete example for this case?

Vitaliy
Mika Koivisto
RE: Search JournalArticles by field in content
11 marzo 2013 18.10
Risposta

Mika Koivisto

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 1505

Data di Iscrizione: 7 agosto 2006

Messaggi recenti

If you look at JournalIndexer you can see how Liferay indexes structured content fields in the seach index. Then you can just execute lucene queries against it just as Mikko suggested. Basically the structure field name is prefixed with web_content/.
Mikko Torri
RE: Search JournalArticles by field in content
11 marzo 2013 23.08
Risposta

Mikko Torri

Punteggio: Junior Member

Messaggi: 33

Data di Iscrizione: 9 maggio 2011

Messaggi recenti

Vitaliy Koshelenko:
Hi, Mikko!

Thanks for your reply. But where should I place this query ? Can you write, plase, the complete example for this case?

Vitaliy


Set the query as the keyword of the search. Be it in Java/JSP/what ever you're using to create the page which lists the contents.
Vitaliy Koshelenko
RE: Search JournalArticles by field in content
12 marzo 2013 7.57
Risposta

Vitaliy Koshelenko

Punteggio: Expert

Messaggi: 271

Data di Iscrizione: 25 marzo 2011

Messaggi recenti

Thanks, guys.
Is this kind of search supported in Liferay 5.2.3 ?
Mika Koivisto
RE: Search JournalArticles by field in content
12 marzo 2013 12.04
Risposta

Mika Koivisto

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 1505

Data di Iscrizione: 7 agosto 2006

Messaggi recenti

Not sure. Just look at JournalIndexer and if it does index like that then it probably supports that kind of query too.
Vitaliy Koshelenko
RE: Search JournalArticles by field in content
25 marzo 2013 4.10
Risposta

Vitaliy Koshelenko

Punteggio: Expert

Messaggi: 271

Data di Iscrizione: 25 marzo 2011

Messaggi recenti

I suppose, it's not supported in Liferay 5.2.3 version, as in Control Panel of Liferay 6.1 when adding field to WebContent structure I can select 'Not Searchable' / 'Searchable - Text' / 'Searchable - Keyword' options, in 5.2.3 this functionality is missing.