cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in retrieving search result

Former Member
0 Kudos

Hi Experts,

I wrote Java Application for Search Using Index Management APIs.

I am not getting any result.

Just look at my code

<b>i have taken some Variable String x="" to test my code</b>

IIndexService indexService =

(IIndexService)ResourceFactory.getInstance().getServiceFactory().getService("IndexmanagementService");

<b> x=x+ "1"+ indexService.getID();</b>

IFederatedSearch federatedSearch =

(IFederatedSearch)indexService.getObjectInstance("federatedSearchInstance");

// get list of all active indexes

//alternatively use the indexService to get indexes by index ID and add them to a list

List listuser=indexService.getActiveIndexes();

<b>x=x+ " 2 " + listuser.size();</b>

// build IQueryEntryList

SearchQueryListBuilder sqb = new SearchQueryListBuilder();

sqb.setSearchTerm(query);

IQueryEntryList qel = sqb.buildSearchQueryList();

<b> x=x+ " 3 " + qel.size();</b>

//search

ISearchSession session = federatedSearch.searchWithSession(qel, listuser,resourseContext);

<b> x= x + " 4 " + session.getTotalNumberResultKeys();</b>

//get the Results

ISearchResultList results = session.getSearchResults(1,session.getTotalNumberResultKeys());

ISearchResultListIterator iter = results.listIterator();

<b> x= x " 5 " results.size();</b>

while (iter.hasNext())

{

ISearchResult result = iter.next();

IResource resource = result.getResource();

IURLGeneratorService url =

(IURLGeneratorService)ResourceFactory.getInstance ().getServiceFactory().getService(IServiceTypesConst.URLGENERATOR_SERVICE);

uri=uri + url.getResourcePageUri(PathKey.CONTENT_ACCESS_PATH,resource.getAccessRID(),null).toString();

<b> x=x+" 6 ";</b>

}

<b> x=x+ " 7 "+uri.length();</b>}

}

return x;

*******************************

The output what i am getting is....

For this line <b> session.getTotalNumberResultKeys(); </b> i am getting output as 1 (one).

Means there is one result.

I am retrieving the results and storing it in 'results' list object

like this

ISearchResultList results = session.getSearchResults(1,session.getTotalNumberResultKeys());

When i say results.size() i am getting 0 as output.

What is this strange behaviour....?

Total results are 1(one)

When i try to retrieve them it says 0(zero) results.

When i perform normal search in protal there also i am getting only one result(when i search * as a search query).

the same i am doing it here.But i am not able to retrieve the result.

To test this application , i am converting this java Class into Webservice and deploying it in searver.

The reason why i am converting it into webservice is , it will be used other portal i.e Sharepoint Portal.(They will call this webservice in their code)

Why is it happening so.

Any one has ideas , where it is going wrong.

Regards

Bala

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Bala,

I saw your thread. I am also facing the same problem. The SearchResultList's size is coming as 0 while session.getNumberResultKeys returns 15..I have the super_admin role assinged to me and also required permissions in index..Did you got any solution to it?

Thanks & Regards,

Udit

Former Member
0 Kudos

HI Udit,

Yes i got the answer to it.

In my case the prblem was with the user credentilas.

When i run the same application from WebDynpro, it was working fine, meanse result list and result keys was same.

But when i run it as java application, i had the problem which you had.

So what i did is, I have checked which user it is taking in WebDynpro and which user it is taking in my java Application. Surprisingly it was different.

So tried with the same user, which it is taking in WebDynpro.

generally by default it takes <b>Guest</b> user in WebDynpro.

So first try this application from webdynpro, if it works fine there.

Take the same user name and pass it from your java application.

It is the problem with user name only.

any way i am sending you my code , have look at it.

public class SearchJavaClass {

String uri = "";

//LinkedList list1 = new LinkedList();

//public String Go(String query) {

public List Go(String query) {

String var =null;

List SearchURL= new ArrayList();

int i=0;

//x=x+"i am in Go";

// com.sap.security.api.IUser nwUser =

// UMFactory.getAuthenticator().getLoggedInUser();

com.sap.security.api.IUser nwUser = null;

try {

//com.sap.security.api.IUser nwUser1 = UMFactory.getUserFactory().getUser("Guest");

//x = x + "nwUser1: "+nwUser1.getName();

nwUser = UMFactory.getUserFactory().getUserByLogonID("Guest");

} catch (UMException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

try {

// Bala start

com.sapportals.portal.security.usermanagement.IUser ep5User =

WPUMFactory.getUserFactory().getEP5User(nwUser);

ResourceContext resourseContext = new ResourceContext(ep5User);

IIndexService indexService =

(IIndexService) ResourceFactory

.getInstance()

.getServiceFactory()

.getService(

"IndexmanagementService");

IFederatedSearch federatedSearch =

(IFederatedSearch) indexService.getObjectInstance(

"federatedSearchInstance");

List listuser = indexService.getActiveIndexes();

SearchQueryListBuilder sqb = new SearchQueryListBuilder();

sqb.setSearchTerm(query);

IQueryEntryList qel = sqb.buildSearchQueryList();

ISearchSession session =

federatedSearch.searchWithSession(

qel,

listuser,

resourseContext);

ISearchResultList results =

session.getSearchResults(1, session.getTotalNumberResultKeys());

ISearchResultListIterator iter = results.listIterator();

//String uri = "";

//ArrayList al= new ArrayList();

//al.add(uri);

//var="";

while (iter.hasNext()) {

var ="";

// SearchVO searchvo = new SearchVO();

ISearchResult result = iter.next();

IResource resource = result.getResource();

IURLGeneratorService url =

(IURLGeneratorService) ResourceFactory

.getInstance()

.getServiceFactory()

.getService(IServiceTypesConst.URLGENERATOR_SERVICE);

uri =

url

.getResourcePageUri(

PathKey.CONTENT_ACCESS_PATH,

resource.getAccessRID(),

null)

.toString();

com.sapportals.wcm.util.uri.IUriReference uri9=url.getResourcePageUri(PathKey.DETAILS_PAGE, resource.getAccessRID(),null);

//@@@@@@@@@com.sapportals.wcm.util.uri.IUriReference uri99 =uri9.appendPath(uri);

IHierarchicalUri uri7 = url.createAbsoluteUri(uri9);

var = uri7.toString();

//searchvo.setIHierarchicalUri(uri7);

// SearchURL.add(i,uri7);

SearchURL.add(i,var);

var="";

i++;

// var = var" "uri7;

// Bala end

}

} catch (ResourceException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UserManagementException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WcmException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

// if(SearchURL.isEmpty())

// return SearchURL ;//+ " No matches have been found";

// else

// //return var;

return SearchURL;

}

}

public static void main(String[] args) {

SearchJavaClass obj = new SearchJavaClass();

obj.Go(" Search Term");

}

}

Regards

Bala

Former Member
0 Kudos

Hi Bala,

Thanks for the reply. I tried changing the user by "Guest" but the results value is still 0...But when I give user as "index_service", I am getting the results.. But, what I am looking for ,are user-specific documents..So, if I give the user id as "index_service", then I am getting the same docs list for every user..So, what changes shall I make..Any Idea??

Thanks & Regards,

Udit

Former Member
0 Kudos

Hi Udit,

I am not sure about user specific search, But in general it doesn't happen.

Is it happens in Portal first?

In case if it happens in our EP Portal, then its possible.

What i feel is, it brings documents based on indexing, data sources assigned to it.

The logic which we are using here is purely on indexing concept.

We are not doing indexing as user specific correct?

Indexing is common for all the users.

remember what ever happens in portal search, that we can replicate with our java program.

In our portal user specific search doesn't happens.

In case if you want to do it, you can give permissions to the documents or folders.

Let me know, what is your exact requirement, then i will try to help you out.

Regards,

Bala

Former Member
0 Kudos

let me know you are writing java application or WebDynpro application ?

And send me your code.

Regards

Bala

Former Member
0 Kudos

Hi Bala,

Actually, I have to show 5 recently added docs for users in their business cards.So,I am creating a portal service which is giving output if I hard-code user id as index_service..I am getting the userid using the uniquename property. But ISearchResultList receives 0 value, and getNumberofKeys has values (I checked). Here is the code that I am using..

public class PropertyRendererRecentlyAdded

implements IStructuredPropertyRenderer {

public Component renderMetaProperty(IMetaName metaName, IMetaContext rendererContext)

throws WcmException {

Component ResultComp=null;

PropertyName uniqueNamePropertyName = new PropertyName(IWcmConst.SAP_WCM_NAMESPACE_COLLABORATION + IWcmConst.NAMESPACE_SEPARATOR + "ume","uniquename");

IProperty uniqueNameProperty = rendererContext.getPropertyMap().get(uniqueNamePropertyName);

String uniqueName=uniqueNameProperty.getStringValue();

StringBuffer message=new StringBuffer("");

if(uniqueName!=null)

{

//used message to check my application

message.append("Uniquename:"uniqueName">>>");

try

{

com.sap.security.api.IUser user=UMFactory.getUserFactory().getUserByUniqueName(uniqueName);

com.sapportals.portal.security.usermanagement.IUser ep5User=WPUMFactory.getUserFactory().getEP5User(user);

IResourceContext context=new ResourceContext(ep5User);

IIndexService indexService =(IIndexService)

ResourceFactory.getInstance().getServiceFactory().getService(IServiceTypesConst.INDEX_SERVICE);

IFederatedSearch federatedSearch = (IFederatedSearch)indexService.getObjectInstance(

IWcmIndexConst.FEDERATED_SEARCH_INSTANCE);

SearchQueryListBuilder sqb = new SearchQueryListBuilder();

sqb.setSearchTerm("*");

IQueryEntryList qel = sqb.buildSearchQueryList();

List indexList = new ArrayList();

String[] index ={"mars_mkt","rooms"};

for(int i=0;i<index.length;i++)

{

message.append("Index Name>>>"indexService.getIndex(index<i>).getIndexName()">>>");

indexList.add(indexService.getIndex(index<i>));

}

ISearchSession session = null;

session = federatedSearch.searchWithSession(qel, indexList, context);

message.append("session.getNumberResultKeys():"session.getNumberResultKeys()">>>");

ISearchResultList results = session.getSearchResults(1,session.getNumberResultKeys());

message.append("session.SearchResultSize :"results.size()">>>");

for(int i=0;i<results.size();i++)

{

for(int j=i1;j<results.size();j+)

{

IResource first= results.get(i).getResource();

IResource second= results.get(j).getResource();

if(first.getCreationDate().after(second.getCreationDate()))

{

IResource temp=first;

first=second;

second=temp;

}

}

}

int x=results.size()>5?5:results.size();

ISearchResultList top5results=results.subList(0,x);

String docNames="";

for(int start=0;start<top5results.size();start++)

{

docNames=top5results.get(start).getResource().getName()" , ";

}

TextView textView=new TextView(message.toString());

ResultComp=textView;

}

catch(Exception u)

{

return new TextView("Exception :"u.getMessage()"::"+u.toString());

}

}//end if

else

{

TextView textView = new TextView("Could not find docs for the user");

ResultComp = textView;

}

return ResultComp;

}

Regards,

Udit

Former Member
0 Kudos

Hi balakrishna,

In order to be able to access the search results normally, the user should have atleast read permison in the index. similarly the user executing the code should have access permissions on the repository that you are searching.

Regards

Ramesh Kotagiri

Former Member
0 Kudos

Hello,

first of all I wonder why there is two times a '1' between '4' and '5' in the result!? Are you sure that you listed the whole code?

Anyway, I do have an idea why you don't get any results from getSearchResults(): the reason might be that the executing user of the code is not allowed to view the search result.

getTotelNumberResultKeys()

returns the number of results that have been found for the given query entry list without checking access permissions.

getSearchResults(...)

returns only results that the executing user is allowed to view!

Please check if there is a difference when executing that code as a super administrator.

Martin

Former Member
0 Kudos

This is what i get as output.

1 indexmanagement 2 2 3 3 4 1 1 5 0 7 0

6 is not printing.

Bala