This post is more than 5 years old
1 Rookie
•
7 Posts
0
2174
September 14th, 2011 14:00
Search for Documents using attributes
Hi,
We have documents stored in Centera cluster and would want to do a search based on some of the attributes.
i was able to run the sample code for search based on attributes but have found a serious contraint. the search criteria only works with a time contraint. a FROM and TO timestamp. and the interval too is very short. so i cannot say a starting date which is months/years ago. if the time interval is big the code fails with a socket error.
Can someone please guide me if i am in the right direction or am i missing something?
code is as follows:
STORE :
i add the following attributes: i tried with the Tag BUT that didnt work. donno how to query by Tag attributes.
theClip.setDescriptionAttribute("filename", filename); | |||
theClip.setDescriptionAttribute("firstName", "Yousuf"); | |||
theClip.setDescriptionAttribute("lastName", "Badar"); | |||
theClip.setDescriptionAttribute("accession", "ACC123456789"); | |||
theClip.setDescriptionAttribute("patientId", "PID123456789"); |
RETRIEVE
Set selectedFields= new HashSet ();
selectedFields.add("creation.date");
selectedFields.add("modification.date");
selectedFields.add("lastName");
selectedFields.add("firstName");
Map fieldRegExps=new HashMap ();
fieldRegExps.put("firstName", "Yousuf");
fieldRegExps.put("lastName", "Badar");
thePool = conPool.getConnection();
try{
TimeZone TZ = TimeZone.getTimeZone("EST");
Calendar clusterTime = Calendar.getInstance(TZ);
Calendar epoch = Calendar.getInstance(TZ);
epoch.setTime(new Date(0));
String start = ConvertDateTimeToString(epoch);
start = "2010.9.9.00.00.01";
from = ConvertDisplayToCalendar(start);
String end = //ConvertDateTimeToString(clusterTime);
"2011.9.10.00.00.01";
to = ConvertDisplayToCalendar(end);
/*
* compile patterns
*/
System.out.println("compiling patterns ...");
Map patterns = new HashMap ();
if(fieldRegExps != null) {
for(Map.Entry e : fieldRegExps.entrySet()) {
try{
Pattern p = Pattern.compile(e.getValue());
patterns.put(e.getKey(), p);
} catch(Exception ex) {
throw new Exception(
String.format("error while parsing regexp '%s' into pattern: %s", e.getValue(), ex.getMessage()), ex);
}
}
}
/*
* create Centerasearch expression
*/
FPQueryExpression exp = new FPQueryExpression();
if(from != null) {
System.out.println(String.format("[query] date from is %s", ConvertDateTimeToString(from)));
exp.setStartTime(from.getTimeInMillis());
} if(to != null) {
System.out.println(String.format("[query] date to is %s", ConvertDateTimeToString(to)));
exp.setEndTime(to.getTimeInMillis());
}
int type = 0;
if(includeExistingClips) {
System.out.println("[query] including existing clips");
type |= FPLibraryConstants.FP_QUERY_TYPE_EXISTING;
}
if(includeDeletedClips) {
System.out.println("[query] including deleted clips");
type |= FPLibraryConstants.FP_QUERY_TYPE_DELETED;
}
exp.setType(type);
StringBuilder buf = new StringBuilder();
for(String field: selectedFields) {
buf.append(field);
buf.append(" ");
exp.selectField(field);
}
System.out.println(String.format("[query] selected fields are %s", buf.toString()));
/*
* create query and do search
*/
System.out.println("creating pool query ...");
FPPoolQuery query = new FPPoolQuery(thePool, exp);
long timeout = -1;
if(queryTimeout != null)
timeout = queryTimeout.longValue();
FPQueryResult result = null;
boolean finished = false;
boolean incomplete = false;
boolean process = false;
String error = null;
Set clipIds = new LinkedHashSet ();
int retries = 0;
int idx = 0;
while(!(finished || incomplete)) {
// fetch next result
LOGGER.trace(String.format("[%03d] fetching result", idx));
result = query.FetchResult(timeout);
process = false;
LOGGER.trace(String.format("[%03d] result is %d", idx, result.getResultCode()));
if(result.getResultCode() != FPLibraryConstants.FP_QUERY_RESULT_CODE_PROGRESS)
retries = 0;
// check status
switch(result.getResultCode()) {
case FPLibraryConstants.FP_QUERY_RESULT_CODE_OK:
process = true;
break;
case FPLibraryConstants.FP_QUERY_RESULT_CODE_INCOMPLETE:
incomplete = true;
break;
case FPLibraryConstants.FP_QUERY_RESULT_CODE_COMPLETE:
case FPLibraryConstants.FP_QUERY_RESULT_CODE_END:
process = true;
finished = true;
break;
case FPLibraryConstants.FP_QUERY_RESULT_CODE_ABORT:
error = "The query has been aborted because of a problem at the server side. The application may want to resubmit the query";
incomplete = true;
break;
case FPLibraryConstants.FP_QUERY_RESULT_CODE_ERROR:
error = "The FetchResult call is aborted because a (platform-specific) error occurred.";
incomplete = true;
break;
case FPLibraryConstants.FP_QUERY_RESULT_CODE_PROGRESS:
if(maxRetries == null) {
error = "query timed out and retries are disabled, aborting search";
incomplete = true;
break;
}
if(retries >= maxRetries.intValue()) {
error = String.format("query timed out maximum number of retries reached (%d), aborting search", maxRetries.intValue());
incomplete = true;
}
retries++;
// System.out.println(String.format("search timed out after %d, going into retry %d / %d", retries, maxRetries.intValue()));
break;
}
idx++;
if(!process)
continue;
// check if all patterns apply
boolean matched = true;
for(Map.Entry e : patterns.entrySet()) {
String fieldName = e.getKey();
String value = result.getField(fieldName);
if((value == null) || (value.trim().length() == 0))
continue;
Matcher m = e.getValue().matcher(value);
if(!m.matches()) {
matched = false;
break;
}
}
if(!matched)
continue;
String clipId = result.getClipID();
System.out.println(clipId + " "+ result.getField("firstName") +" "
+ result.getField("lastName") + " " + result.getField("creation.date")+ " "
+ result.getField("modification.date"));
clipIds.add(clipId);
}
} catch(Exception e) {
throw new Exception(String.format("error while processing Centera search: %s", e.getMessage()), e);
}
kim_marivoet
41 Posts
0
September 15th, 2011 00:00
At first sight it looks ok, and using large time intervals should work. Maybe something to try: use '0' as the starting time. The query will start with the first clipever written to the system. This should certainly work and maybe it can already give you some information to pinpoint your problem.
Brs,
Kim Marivoet
mckeown_paul
409 Posts
1
September 15th, 2011 04:00
To add to this. The socket error you are getting is normally an indication of a network error (the sdk got an error on a socket read). It could also be an error on the cluster that caused socket error.
try though what marivk suuggested, see if you get the error using jcasscript.
kim_marivoet
41 Posts
1
September 15th, 2011 04:00
This can have various reasons, also mistakes in your own source code. To rule out a problem with the Centera you could do the same query as you're doing in your own software using JCASScript (look in downloads or something). You can create a query, select the field you select and run the query. If that works then there is probably something wrong with your software/integration. If it doesn't work, then I guess you have to contact EMC support to take a look at the server.
yousufbadar
1 Rookie
•
7 Posts
0
September 15th, 2011 04:00
it did work. Thank you for pointing that out!!!!
i am getting the following error after a while. results start printing but then all of a sudden this appears. what could be the reason.
java.lang.Exception: error while processing Centera search: Error on network socket (transid='w7-z400-22/6/QUERY')
at com.labcorp.ncp.cas.dao.CasDaoImpl.searchQuery(CasDaoImpl.java:943)
at com.labcorp.ncp.cas.dao.CasDaoImpl.getFilesFromCas(CasDaoImpl.java:960)
at com.labcorp.ncp.cas.dao.CasDaoTest.searchFiles(CasDaoTest.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
...
Caused by: com.filepool.fplibrary.FPLibraryException: Error on network socket (transid='w7-z400-22/6/QUERY')
at com.filepool.fplibrary.FPPoolQuery.FetchResult(Unknown Source)
at com.labcorp.ncp.cas.dao.CasDaoImpl.searchQuery(CasDaoImpl.java:859)
... 25 more
yousufbadar
1 Rookie
•
7 Posts
0
September 15th, 2011 07:00
i get this:
Performing clip query
Query Expression Properties:
Start Time: UNBOUNDED
End Time : UNBOUNDED
Type : EXISTING
SDK Error Occurred:
Error Number: -10204
System Error: 0
Error: FP_OPERATION_NOT_ALLOWED
Error Class: Client Error
Trace: FPPoolQuery::FetchResult(120000)
Number of clips returned: 0
All results returned: False
Point of incompletion: Immediate
capabilities are :
CASPool Capabilities:
Supports Read Operations: True
Read Pools: default,b9031e52-1dd1-11b2-bba6-ff13179e47e2-8
1dd2-11b2-bd69-b120f92ae9f1-10
Supports Write Operations: True
Write Pools: default,b9031e52-1dd1-11b2-bba6-ff13179e47e2-8
1dd2-11b2-bd69-b120f92ae9f1-10
Supports Purge Operations: False
Purge Pools:
Supports Delete Operations: True
Delete Pools: default,b9031e52-1dd1-11b2-bba6-ff13179e47e2-8
1dd2-11b2-bd69-b120f92ae9f1-10
Supports Exist Operations: True
Exist Pools: default,b9031e52-1dd1-11b2-bba6-ff13179e47e2-8
1dd2-11b2-bd69-b120f92ae9f1-10
Supports Query Operations: True
Query Pools: default,b9031e52-1dd1-11b2-bba6-ff13179e47e2-8
1dd2-11b2-bd69-b120f92ae9f1-10
Supports PrivilegedDelete : False
PrivilegedDelete Pools:
Supports Monitor Operations: True
PoolMappings Pools:
PoolMappings Profiles:
Supports DeletionLogging : True
Default Retention Period: 0
Blob Naming Scheme: MD5,MG
Cluster Mode: basic
Minimum Fixed Retention: 0
Maximum Fixed Retention: -1
Minimum Variable Retention: 0
Maximum Variable Retention: -1
mckeown_paul
409 Posts
0
September 16th, 2011 07:00
yes
java -jar jcasscript
>poolopen
kim_marivoet
41 Posts
0
September 16th, 2011 07:00
What kind of connection string do you specify with JCASScript ? Is it the same one as you used in your own software?
yousufbadar
1 Rookie
•
7 Posts
0
September 16th, 2011 08:00
Thanks Kim and Paul for stepping forward to help. i appreciate it.
Paul
yes. that is exactly what i used. my application is able to hit the servers and do a search but CASScript fails with FP_OPERATION_NOT_ALLOWED.
i was able to get away with socket error after i increased the query timeout. BUT when the range of to and from date is small the results are retrieved. if the range is more it doesnt come back with a response but kind of hangs. can you please guide me on how do i fix this issue.
mckeown_paul
409 Posts
0
September 16th, 2011 08:00
At the moment I can't think of why you are getting this. I would put a support call into emc support on this
yousufbadar
1 Rookie
•
7 Posts
0
September 16th, 2011 09:00
how does this work?
result = query.FetchResult(timeout);
does it get one record at a time ? and how does it know which record to get??