RE: Indexable field search, how?

Ervinas Marocka, modified 6 Years ago. Junior Member Posts: 31 Join Date: 10/8/18 Recent Posts
Hello,

Got a problem. Can't solve this.

The problem is about searching. I'm trying to code JournalArticle search by indexable keyword before create method. 

I have created a structure of webcontent and having a field called "regNumber" which is "Indexable-Keyword". 

How should i perform a quick search? I just need an algorythm to know what exactly I have to do. Tried everything I know about the search, but can't seach for this. I need to search BY THAT SPECIFIC FIELD ONLY and the value HAVE TO MATCH 100%. 

The reason i need this is to check if the value already exists before JournalArticle creates.

I'm using Liferay CE 7.0.6 GA7.

Any help would be great.

Thanks.
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
If you need to match on one field only, I wouldn't use the search by keyword.  I mean, if anything calls for a direct DB query, need to "search by that specific field only and value has to match 100%" does.
Ervinas Marocka, modified 6 Years ago. Junior Member Posts: 31 Join Date: 10/8/18 Recent Posts

David H Nebinger:

If you need to match on one field only, I wouldn't use the search by keyword.  I mean, if anything calls for a direct DB query, need to "search by that specific field only and value has to match 100%" does.


Thanks for the answer, David.

Okay, so got the point that I need to query direct to database? But it won't be efficient enough because of the Journal Article content storing as clob XML. If i have to query every single article one by one and then look for parameter in XML. Am I right? Any other solution?
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

Even though it's a clob, I would start w/ trying a "like" match based on a string that contains the xml fragment to key off of.  It may actually perform better than what you give it credit for.

If it doesn't, well then we can take the next step and explore an IndexPostProcessor and a modification of the query to boost and filter based upon the key field...

But start w/ the simpler solution first before taking the hard road.

Ervinas Marocka, modified 6 Years ago. Junior Member Posts: 31 Join Date: 10/8/18 Recent Posts
David H Nebinger:

Even though it's a clob, I would start w/ trying a "like" match based on a string that contains the xml fragment to key off of.  It may actually perform better than what you give it credit for.

If it doesn't, well then we can take the next step and explore an IndexPostProcessor and a modification of the query to boost and filter based upon the key field...

But start w/ the simpler solution first before taking the hard road.

Interesting. You mean using DynamicQuery for that? If so, i'm actaullly trying like that :

                ClassLoader cl = PortalClassLoaderUtil.getClassLoader();
                DynamicQuery dynamicQuery = JournalArticleLocalServiceUtil.dynamicQuery()
                            .add(PropertyFactoryUtil.forName("content").like("%<dynamic-content><![CDATA[" + regNumber + "]]></dynamic-content>%"));
                List results = JournalArticleLocalServiceUtil.dynamicQuery(dynamicQuery);
 

But I get the results size = 0, not sure why. Not sure if this is the correct approach for your answers. 

thumbnail
Jorge Díaz, modified 6 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts

Hi Ervinas Marocka and David Nebinger,

 

In my opinion doing a "like" SQL query in JournalArticle clob column is a bad idea, you will have thoughput problems and your DBA will complain in case of detecting all that "like" queries in case of any problem in database side.

 

You should query Elasticsearch/Solr index. You have information about how to query JournalArticle filtering by DDM fields in following posts:

(note: second and third link are related to 6.2 version, but 7.x queries should be very similar)

 

In Liferay Portal 7.x, the names of DDM fields that you have to query are built in DDMIndexerImpl.encodeName(...) method, see:

 

DDM fields names follows following pattern:

  • Fields that are configured as keyword: ddm__keyword__{structrureId}__{fieldname}_{locale}

  • Other fields: ddm__{structrureId}__{fieldname}_{locale}

 

Note: in order to get structureId, you should query DDMStructure filtering by structureKey, if you hardcode the structureId, you can have problems in case you export/import the structure because structureId is recalculated during import process.

Ervinas Marocka, modified 6 Years ago. Junior Member Posts: 31 Join Date: 10/8/18 Recent Posts
Jorge Díaz:

Hi Ervinas Marocka and David Nebinger,

 

In my opinion doing a "like" SQL query in JournalArticle clob column is a bad idea, you will have thoughput problems and your DBA will complain in case of detecting all that "like" queries in case of any problem in database side.

 

You should query Elasticsearch/Solr index. You have information about how to query JournalArticle filtering by DDM fields in following posts:

(note: second and third link are related to 6.2 version, but 7.x queries should be very similar)

 

In Liferay Portal 7.x, the names of DDM fields that you have to query are built in DDMIndexerImpl.encodeName(...) method, see:

 

DDM fields names follows following pattern:

  • Fields that are configured as keyword: ddm__keyword__{structrureId}__{fieldname}_{locale}

  • Other fields: ddm__{structrureId}__{fieldname}_{locale}

 

Note: in order to get structureId, you should query DDMStructure filtering by structureKey, if you hardcode the structureId, you can have problems in case you export/import the structure because structureId is recalculated during import process.

Thanks, this kinda helped me to solve my problem. :)

 
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Just to sprinkle in an alternative here, mostly because the autogenerated index field name is gross (I know it's a necessary evil, but still). Sometimes what I do is I set the structure field to NOT be indexable so that I avoid the ddm_... field. Then I create an IndexPostProcessor for where you can access the Document object before it is added to the index. In this class I create a new Field object, with the name _I_ want to use and othen add it to the document. I only use this trick though when I don't need the field value to be included as part of the mash up "content" field. So for example, I want to have a filter that does exact matches type thing, or I want to create a facet. 

 

Just some food for thought and another example of the power of Liferay -- multiple ways to solve the same problem. 

Kishan Agrawal, modified 6 Years ago. New Member Posts: 24 Join Date: 1/8/18 Recent Posts

Hello,

You can achive this by Two ways 

IF you want to search for only single field with exect keyword match you can go for liferay feature of elstic serach (using indexer class)

and if you want to serach with combination of field you can go for boolean query    

both would give your work done.

Note :- elastic search works on keyword base search 

Ervinas Marocka, modified 6 Years ago. Junior Member Posts: 31 Join Date: 10/8/18 Recent Posts
Kishan Agrawal:

Hello,

You can achive this by Two ways 

IF you want to search for only single field with exect keyword match you can go for liferay feature of elstic serach (using indexer class)

and if you want to serach with combination of field you can go for boolean query    

both would give your work done.

Note :- elastic search works on keyword base search 

Hello Kishan,

You're talking about this? https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-a-guestbook-indexer



 
Kishan Agrawal, modified 6 Years ago. New Member Posts: 24 Join Date: 1/8/18 Recent Posts
Ervinas Marocka:
Kishan Agrawal:

Hello,

You can achive this by Two ways 

IF you want to search for only single field with exect keyword match you can go for liferay feature of elstic serach (using indexer class)

and if you want to serach with combination of field you can go for boolean query    

both would give your work done.

Note :- elastic search works on keyword base search 

Hello Kishan,

You're talking about this? https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/creating-a-guestbook-indexer



 

Yes Ervinas Marocka. 

I was talikng about something like it. 
Although we can use "like" or that kind of querys that will interact with your database and give you result.

but i would suggest to use elastic search which is used by liferay.

bcz it will reduce your complexity and databse call that will improve your working of project and server maintaince

Bcz elastice search uses kibana so all the time when you heat for search it will not make interaction with your database.