List objects;
logger.debug("IN");
try {
UserProfile profile = (UserProfile)getUserProfile();
Vector<String> fieldsToSearch = new Vector<String>();
String valueFilter = getAttributeAsString(SpagoBIConstants.VALUE_FILTER);
String attributes = getAttributeAsString(ATTRIBUTES);
String metaDataToSearch = null;
if(attributes != null){
if(attributes.equalsIgnoreCase("ALL")){//SEARCH IN ALL FIELDS
fieldsToSearch.add(IndexingConstants.BIOBJ_LABEL);
fieldsToSearch.add(IndexingConstants.BIOBJ_NAME);
fieldsToSearch.add(IndexingConstants.BIOBJ_DESCR);
fieldsToSearch.add(IndexingConstants.METADATA);
//search metadata binary content
fieldsToSearch.add(IndexingConstants.CONTENTS);
//search subobject fields
fieldsToSearch.add(IndexingConstants.SUBOBJ_DESCR);
fieldsToSearch.add(IndexingConstants.SUBOBJ_NAME);
}else if(attributes.equalsIgnoreCase("LABEL")){//SEARCH IN LABEL DOC
fieldsToSearch.add(IndexingConstants.BIOBJ_LABEL);
}else if(attributes.equalsIgnoreCase("NAME")){//SEARCH IN NAME DOC
fieldsToSearch.add(IndexingConstants.BIOBJ_NAME);
}else if(attributes.equalsIgnoreCase("DESCRIPTION")){//SEARCH IN DESCRIPTION DOC
fieldsToSearch.add(IndexingConstants.BIOBJ_DESCR);
}else{//SEARCH IN CATEGORIES DOC
//get categories name
metaDataToSearch = attributes;
//fieldsToSearch.add(IndexingConstants.METADATA);
fieldsToSearch.add(IndexingConstants.CONTENTS);
}
}
boolean similar = getAttributeAsBoolean(SIMILAR);
logger.debug("Parameter [" + SpagoBIConstants.VALUE_FILTER + "] is equal to [" + valueFilter + "]");
String indexBasePath = "";
String jndiBean = SingletonConfig.getInstance().getConfigValue("SPAGOBI.RESOURCE_PATH_JNDI_NAME");
if (jndiBean != null) {
indexBasePath = SpagoBIUtilities.readJndiResource(jndiBean);
}
String index = indexBasePath+"/idx";
IndexReader reader;
HashMap returned = null;
try{
reader = IndexReader.open(FSDirectory.open(new File(index)), true);
// read-only=true
IndexSearcher searcher = new IndexSearcher(reader);
String[] fields = new String[fieldsToSearch.size()];
fieldsToSearch.toArray(fields);
//getting documents
if(similar){
returned = LuceneSearcher.searchIndexFuzzy(searcher, valueFilter, index, fields, metaDataToSearch);
}else{
returned = LuceneSearcher.searchIndex(searcher, valueFilter, index, fields, metaDataToSearch);
}
ScoreDoc [] hits = (ScoreDoc [])returned.get("hits");
objects = new ArrayList();
if(hits != null) {
for(int i=0; i<hits.length; i++) {
ScoreDoc hit = hits[i];
Document doc = searcher.doc(hit.doc);
String biobjId = doc.get(IndexingConstants.BIOBJ_ID);
BIObject obj =DAOFactory.getBIObjectDAO().loadBIObjectForDetail(Integer.valueOf(biobjId));
if(obj != null){
boolean canSee = ObjectsAccessVerifier.canSee(obj, profile);
if (canSee) {
objects.add(obj);
}
}
}
}
searcher.close();
} catch (CorruptIndexException e) {
logger.error(e.getMessage(), e);
throw new SpagoBIException("Index corrupted", e);
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new SpagoBIException("Unable to read index", e);
} // only searching, so
catch (ParseException e) {
logger.error(e.getMessage(), e);
throw new SpagoBIException("Wrong query syntax", e);
}
JSONArray documentsJSON = (JSONArray)SerializerFactory.getSerializer("application/json").serialize( objects, null);
for(int i=0; i<documentsJSON.length();i++){
JSONObject jsonobj = documentsJSON.getJSONObject(i);
String biobjid = jsonobj.getString("id");
String summary = (String)returned.get(biobjid);
jsonobj.put("summary", summary);
String views = (String)returned.get(biobjid+"-views");
jsonobj.put("views", views);
}
Collection func = profile.getFunctionalities();
if(func.contains("SeeMetadataFunctionality")){
JSONObject showmetadataAction = new JSONObject();
showmetadataAction.put("name", "showmetadata");
showmetadataAction.put("description", "Show Metadata");