Foros de discusión

Tag & search lfr user [RESOLVED]

thumbnail
Rishi Dev Gupta, modificado hace 15 años.

Tag & search lfr user [RESOLVED]

Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
Hi all

I have a requirement where i need the functionality to be able to set tags against the liferay user (which the team is able to do so). Now using the default Search portlet I need that user should not only be search able through name but also the tags associated with him/her.

The functionality should look same as we given by liferay wiki or blogs or journal content.

Does anybody have idea how to go for searching the user based on tags?

Thanks
Rishi
thumbnail
Victor Zorin, modificado hace 15 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
To override user search procedures, make your own class my modifying com.liferay.portlet.directory.util.DirectoryOpenSearchImpl class which is in portal-impl pack.
After that, change <open-search-class> entry for portlet 11 in liferay-portlet.xml. After portal restart, your own class will be used by Tools->Search portlet.

Up to version 5.1+, unlike wiki and blogs and others, directory search is not implemented using lucene, but via direct sql queries. If it was lucene, the applied change would be absolutely minimal and quick.

From 5.2, it has started using indexing engine, for details see class com.liferay.portal.service.impl.UserLocalServiceImpl (look for Hits word). You can take this search(...) method and incorporate it directly within your open-search-class. Do not forget to add another line that would include tag-based search:
searchQuery.addTerm(com.liferay.portal.kernel.search.Field.TAGS_ENTRIES, keywords);
thumbnail
Rishi Dev Gupta, modificado hace 15 años.

RE: Tag & search lfr user

Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
Thanks Victor

I am using LFR 5.2.1 with mysql on jre 6 platform.

Till now what I tried out is making a copy of UserLocalServiceImpl.java in ext enviornment with same package as in source and adding the following code in search method


                        if (Validator.isNotNull(firstName)) {
				searchQuery.addTerm(Field.TAGS_ENTRIES, firstName);
				System.out.println("-----0"+firstName);
				
			}


Also kept the search class entry in liferay-portlet.xml the same way as it was orginal.

What I tried to do above is I want to override the implementation of search method. But it didn't worked.

Now I am going your way, making the custom class and adding it to the xml.
thumbnail
Rishi Dev Gupta, modificado hace 15 años.

RE: Tag & search lfr user

Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
Not successfull till now

What i have done is


1. I have created a class com.liferay.portlet.user.UserOpenSearchImpl.java file in ext-impl


public class UserOpenSearchImpl extends HitsOpenSearchImpl {
	
	public static final String SEARCH_PATH = "/c/directory/open_search";

	public static final String TITLE = "Liferay Directory Search: ";
	
	public Hits getHits(long companyId, String keywords, int start, int end) throws Exception {
		return UserLocalServiceUtil.search(
			companyId, keywords, true, null, start, end, new com.liferay.portal.kernel.search.Sort() );
	}
	
	public String getSearchPath() {
		return SEARCH_PATH;
	}
	
	public String getTitle(String keywords) {
		return TITLE + keywords;
	}
		private static Log _log =
			 LogFactoryUtil.getLog(UserOpenSearchImpl.class);
		
}



and replace the entry in portlet 11 in liferay-portelt.xml with this one

<open-search-class>com.liferay.portlet.user.UserOpenSearchImpl</open-search-class>



Now i have copied the com.liferay.portal.service.impl.UserLocalServiceImpl and added the below code to search method
 searchQuery.addTerm(Field.TAGS_ENTRIES, firstName, true); 




But the thing is I am not getting any results for tag based search

I can get the search working by user details like first name, middlename, suranme, screen name but not by tag added against user.

Do we have to make the entries of tag in lucene also, as this search is based on lucene.
thumbnail
Victor Zorin, modificado hace 15 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
1. Can you make sure that within lucene users have tag values. For verifying this, print out lucene records as described below:

			for (int i = 0; i &lt; hits.getDocs().length; i++) {
				com.liferay.portal.kernel.search.Document doc = hits.doc(i);

				java.util.Iterator<com.liferay.portal.kernel.search.field> it = doc
						.getFields().values().iterator();
				while (it.hasNext()) {
					com.liferay.portal.kernel.search.Field field = it.next();
					logger.info(field.getName() + "=" + field.getValue());
				}
                                                             }

</com.liferay.portal.kernel.search.field>

2. In your code it looks like you search for lucene entries that have tags that are first names,
searchQuery.addTerm(Field.TAGS_ENTRIES, firstName, true); 
Is this what you expect? Or you need to addTerm(TAGS_ENTRIES, keywords).
3. Another note, from your <open-search-class> I would not be calling UserLocalServiceUtil.search(...), but instead inserted lucene code into it. This way you would not have to modify core UserLocalServiceUtil class.
thumbnail
Rishi Dev Gupta, modificado hace 15 años.

RE: Tag & search lfr user

Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
Hi Victor

1. I have tried your code but for hits but it is coming empty means that my search is not working as it should be on user.

2. Its the same thing as using "keywords" as all the user properties like firstname, surname, middlename etc are assigned the value of "keyword" variable. So it does not matter much here.

3. I haven't checked out the lucene code yet, Can you tell me where I can find one.


Also the issue is when LFR hasn't provided the tag based search on user like we have with wiki or blogs, so there won't be any implementation in LFR source to find user using tags through lucene as I think currently the code won't be making any entries to lucene.

What my team mate did for tagging user is, he used the tag library
liferay-ui:tags-selector
and invoked the
com.liferay.portlet.tags.service.impl.TagsEntryLocalServiceImpl
 checkEntries(long userId, long groupId, String[] names)


So is the right approach to make entries in database and make it searchable through lucene.
thumbnail
Victor Zorin, modificado hace 15 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
Rishi, I'll post one of my classes, that I am using for own Global Search Portlet. have a look. It is not searching for User but for any entry, that has been submitted by given portletIds in a given set of cumminity Ids. Code is below, see if it makes sense to you. I do not think that it is going to be very much different for Users:

	public Hits search(long companyId, String[] portletIds, long groupIds[],
			String keywords, SearchConfigForm configForm, int start, int end)
			throws SystemException {

		try {
			BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
			if (portletIds.length &gt; 0) {
				BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();
				for (int i = 0; i &lt; portletIds.length; i++) {
					TermQuery termQuery = TermQueryFactoryUtil.create(
							"portletId", portletIds[i]);

					portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
				}
				contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
			}

			if (groupIds.length &gt; 0) {
				BooleanQuery groupIdsQuery = BooleanQueryFactoryUtil.create();

				for (long groupId : groupIds) {
					TermQuery termQuery = TermQueryFactoryUtil.create(
							"groupId", groupId);

					groupIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
				}

				contextQuery.add(groupIdsQuery, BooleanClauseOccur.MUST);
			}

			BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

			if (Validator.isNotNull(keywords)) {
				if (configForm.getSearchByTitle()) {
					searchQuery.addTerm(Field.TITLE, keywords);
				}
				if (configForm.getSearchByContent()) {
					searchQuery.addTerm(Field.CONTENT, keywords);
				}
				searchQuery.addTerm(Field.PROPERTIES, keywords);
				searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);
			}

			BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();

			fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

			if (searchQuery.clauses().size() &gt; 0) {
				fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
			}
			//logger.info("all fullQuery=" + fullQuery.toString());
			Sort[] sorts = new Sort[1];
			Sort sort = new Sort();
			sort.setFieldName("score");
			sort.setType(Sort.SCORE_TYPE);
			sort.setReverse(false);
			sorts[0] = sort;
			Hits hits = SearchEngineUtil.search(companyId, fullQuery, sorts,
					start, end);
			//Hits hits = SearchEngineUtil.search(companyId, fullQuery, start, end);
			//logger.info("all found hits " + hits.getLength());
			return hits;
		} catch (Exception e) {
			logger.error("error " + e.getMessage());
			return null;
		}
	}



Edited: try to run it using Directory portlet Id, attempt to fetch at least one user and print all document attributes as in previous messages. I am not sure whether you have users with tag attributes as well, as never tried it myself.
thumbnail
Rishi Dev Gupta, modificado hace 15 años.

RE: Tag & search lfr user

Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
Victor,
I have tried using the code posted by you above, Infact its almost the same code that I have implemented keeping Wiki portlet search as base. I have tried it using with 2 different portlet ids --> Directory-11, Enterprise Admin user-125 (used currently by directory open search class) but not able to retrieve any results.

Findings

1. I was further looking into search and found the com.liferay.portlet.enterpriseadmin.util.UserIndexer.java class. When I looked for its references in lfr source, its called every time the user object is added/edited/deleted.

2. When I compared the com.liferay.portlet.wiki.util.Indexer.java for wiki portlet with UserIndexer.java, I found that they are nowhere refer to tag entries class/table. Thus I want to know is the indexer class playing any role while we search for any entity in lfr. If yes then seeing the user indexing code it means that currently the user search does not accommodate searching based on tags whether we make entries in lfr table
tagsentry/tagsasset (as I have done) or pass the tag entry criteria in out search code (as told by you).

3. If the above is true can anybody please specify what exact steps I need to work out to make the LFR user searchable through tags also.


Rishi
thumbnail
Rishi Dev Gupta, modificado hace 15 años.

RE: Tag & search lfr user

Expert Mensajes: 255 Fecha de incorporación: 23/11/08 Mensajes recientes
I am able to get it working now.
As mentioned in my last post I was heading in the right direction.

1. Currently there is no tag based lucene search implemented in liferay. So what I did is I made changes in the Indexer class for user, so that the user tag information is indexed along with other user details.

2. Implemented the search query code which will search for tags using the criteria key Field.TAGS_ENTRIES
and it worked fine.
thumbnail
Victor Zorin, modificado hace 15 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
Excellent.
In this case, non-existence of tags for users was always the primary suspect. So, when someone builds a specialized search query, it is important to be able to print out lucene doc attributes and check which attributes are indexed and what are the values of those attributes.

It is also worthwhile to mention that, in the past, lucene attribute set was changing between portal releases. Make sure that you review your custom lucene queries when upgrading to newer LR versions.
thumbnail
Chris Whittle, modificado hace 14 años.

RE: Tag & search lfr user

Expert Mensajes: 462 Fecha de incorporación: 17/09/08 Mensajes recientes
Victor is it possible to change the search portlet to only look at the community they are in? Due to the permission holes in the current search of the Enterprise editions we need to limit have tried to implement the permission changes that are in the non EE versions but it's causing issues and so I'm looking at other options.... Thanks Whitt
thumbnail
Victor Zorin, modificado hace 14 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
Chris, it should not be the problem. Which one of EEs are you using? Which part did you try to apply the changes in?
Generally, it is important to pass groupId otherwise you will get access to data across all communities.. I remember Parul did similar changes, have a look at her threads.
thumbnail
Chris Whittle, modificado hace 14 años.

RE: Tag & search lfr user

Expert Mensajes: 462 Fecha de incorporación: 17/09/08 Mensajes recientes
I ended up getting it to work for everything except Directory (which we deactivated) here is my code for the next person who needs it... The next step is to get non-permissioned results to not show in the list.. With Brunos help we tried to backport the ones from the latest community edition but had stability issues so I had to back them out... Victor or anyone do you have a solution for hiding content you don't have access to in searches? my early version was a JSP version but it screwed up pagnation and counts... Oh yeah we're using 5.1.5EE
thumbnail
Victor Zorin, modificado hace 14 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
Victor or anyone do you have a solution for hiding content ...

Hiding on rendering level is not going to help here, the displayed result will not correlate with the common statistics data that is also displayed. (As I mentioned before, check Parul posts). Patching is required at lucene query level, but liferay methods do not allow for the direct propagation of additional parameters, that are required for the enforcement of proper permisssioning.
To share own experience, a couple of years ago we decided to take search result delivery into own hands. No regrets so far as this is one of the primary functions in corporate environments. It gave clients true group-wise search capability and plenty of configuration freedom at no extra cost. For us, it has opened a door wide for a range of enhancements, such as corporate network search (no need to do uploading any more), search query and search action logging and analysis. Some absolutely stunning discoveries are made when such analysis is presented to marketing. Having own search has also allowed us to kick-off the development of a suggestive framework, similar to google/yahoo/facebook, but across all portal facilities.
thumbnail
Chris Whittle, modificado hace 14 años.

RE: Tag & search lfr user

Expert Mensajes: 462 Fecha de incorporación: 17/09/08 Mensajes recientes
Victor, What do you think about this? http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1609212 here is my first attempt to do permission and control them from the jsp but that of course breaks pagnation... What if i moved the looping through the hits to the newly customized OpenSearchImpl java files so it only returns the hits filtered by permissions....
thumbnail
Victor Zorin, modificado hace 14 años.

RE: Tag & search lfr user

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
Had a look ...

Question 1: do you really need to use roles' level for limiting your search, or group-based membership will satisfy your requirements?
Question 2: Are you using 'overall' search portlet or specific ones, such as doclib, webcontent, etc ? They have different implementation paths and classes.
thumbnail
Chris Whittle, modificado hace 14 años.

RE: Tag & search lfr user

Expert Mensajes: 462 Fecha de incorporación: 17/09/08 Mensajes recientes
1) Because the users are controlling the permissions and they are all role based I have to stick with that...
2) Both... I found out yesterday that the portlets are using a little different and so I am changing the search.jsp for each of the content portlets to use the new OpenSearchImpl I've created...

I know it's not the best but we currently don't have any better options...
I'm about done I'll post it sometime today and see what you think....
inTest inTest inTest, modificado hace 14 años.

RE: Tag & search lfr user

New Member Mensajes: 4 Fecha de incorporación: 1/09/09 Mensajes recientes
Hello,
I'm new to LFR, so excuse me if the question is trivial.
I what to add the filtering by tag functionality to web content portlet.
As I understand it might be also not implemented. Am I wrong? Any suggestions how to implemnt?
Thanks,
beginer
thumbnail
Namrata Hangal, modificado hace 13 años.

RE: Tag & search lfr user

Regular Member Mensajes: 161 Fecha de incorporación: 27/07/10 Mensajes recientes
Hi all,

I'm looking for a customized search that can filter documents/ content based on title, date of creation, author, content type and keywords.

I understand that title and keyword based search is already a part of the Search portlet (federated search). But, what needs to be done to include the other filters in the search?

I'm a beginner, so, a detailed documentation would be more helpful to me.

Appreciate any help.

Regards,
Namrata
thumbnail
Krati Gupta, modificado hace 13 años.

RE: Tag & search lfr user

Regular Member Mensajes: 119 Fecha de incorporación: 5/12/08 Mensajes recientes
HI All,

I have a requirement like that , I have add extra field in Directory portlet as I want to search user from custom attribute Location apart from user first name , middle name ,last name , screen name and email address.

Now please tell what all files need to be changed for searching user from custom attribute Location .

Please help as soon as possible it is on urgent basis.
thumbnail
Namrata Hangal, modificado hace 13 años.

RE: Tag & search lfr user

Regular Member Mensajes: 161 Fecha de incorporación: 27/07/10 Mensajes recientes
Hi Krati,

I am not too sure, but I guess you will have to check the Directory model structure first..

Regards,
Namrata
thumbnail
Krati Gupta, modificado hace 13 años.

RE: Tag & search lfr user

Regular Member Mensajes: 119 Fecha de incorporación: 5/12/08 Mensajes recientes
Hi Namrata,

I had checked the structure , but unable to figure out what code and in which file it need to changed .
thumbnail
Namrata Hangal, modificado hace 13 años.

RE: Tag & search lfr user

Regular Member Mensajes: 161 Fecha de incorporación: 27/07/10 Mensajes recientes
Hi Krati,

Being new myself (I'm sure you may have noticed emoticon ), I can't help you much, because I am myself looking into customization of Document Library Search.

But for a start, I would suggest you download the liferay source, if you haven't already.

You could check liferay_portal_home/tomcat/root/html/portlets/directory and check out all the files there. I usually start with view.jsp.

After that, in the source code, you can check portal-impl,service,util/src/com/liferay/portal (& portlet)/directory and try to find missing links.

The search implementation is I think the DirectoryOpenSearchImpl.java, not sure again!

Just trying to help someone who's in a similar situation as myself!

Regards,
Namrata
Amit Shukla, modificado hace 11 años.

RE: Tag & search lfr user

Junior Member Mensajes: 93 Fecha de incorporación: 7/06/12 Mensajes recientes
Hi all,
I am looking customization for document library search.

I have added a dialog (-->Advance search) in View,jsp (original core of life ray) and on click of this dialog a form will open as a pop Up. This pop up form has conatains

custom attributes names and their values as drop down . after selection of custom attributes values user click on search button and now i want to display result of search.

for this a am writing a ext plugin .First part is working means on click of advance search -----a pop up form will open but on click of pop up form submit button --nothing is happen (means action is not working )
I have written following class
View.jsp--(liferay core's modified by me)
advance search .jsp-----(for the pop up forms)
advanceresource _search .jsp---(paralel tp serach_resource.jsp of liferay core)
advancesearchactiob,java---( customized class)
Strusts-config-ext.xml
tile-def.xml
Plesae any body help me . or tell me better way to do this task..







Please any one have idea about that.

Thanks
Amit
Amit Shukla, modificado hace 11 años.

RE: Tag & search lfr user

Junior Member Mensajes: 93 Fecha de incorporación: 7/06/12 Mensajes recientes
Hi Namrta,

I am trying for customization of Document Library Search.Can you guide me how should I approach this?

Thanks
Amit Shukla