diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/SearchQueryHandler.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/SearchQueryHandler.java deleted file mode 100644 index 5d5f4cf59..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/SearchQueryHandler.java +++ /dev/null @@ -1,732 +0,0 @@ -package edu.cornell.mannlib.vitro.webapp.search.beans; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.servlet.ServletContext; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.QuerySolutionMap; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.Syntax; -import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.Property; -import com.hp.hpl.jena.rdf.model.RDFNode; -import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.rdf.model.ResourceFactory; -import com.hp.hpl.jena.rdf.model.StmtIterator; -import com.hp.hpl.jena.shared.Lock; -import com.hp.hpl.jena.vocabulary.RDF; -import java.util.HashSet; -import java.util.Set; - -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; - -public class SearchQueryHandler { - - private OntModel fullModel; - private String contextNodeURI; - private int totalInd; - private static final String prefix = "prefix owl: " - + " prefix vitroDisplay: " - + " prefix rdf: " - + " prefix core: " - + " prefix foaf: " - + " prefix rdfs: " - + " prefix localNav: " - + " prefix bibo: "; - //private String query = ""; - -// private static final String queryForEducationalTraining = "SELECT ?query WHERE {" + -// "?searchConfig <"+ DisplayVocabulary.QUERY_FOR_EDUCATIONAL_TRAINING + "> ?query . }"; - - private static Log log = LogFactory.getLog(SearchQueryHandler.class); - - public SearchQueryHandler(String contextNodeURI, - OntModel displayOntModel, ServletContext context) { - this.fullModel = ModelContext.getJenaOntModel(context); - this.contextNodeURI = contextNodeURI; - this.totalInd = fullModel.listIndividuals().toList().size(); - //query = getQueryFromModel(contextNodeURI, displayOntModel); - } - - /* - * bk392 : The original idea behind writing up this method was to check - * if I can read the queries from search.n3, write them to the displayOntModel(during startup) and - * read them in this class. - * - * Eventually, its going to be like that. All these hardcoded queries - * will go into search.n3 and will be written into the display model. - * ContextNodesInclusionFactors gets the queries out from the display Model - * and fires them, gets the values, concatenates them and passes them back to - * IndividualToSolrDoc. - */ -// private String getQueryFromModel(String uri, OntModel displayOntModel) { -// -// String resultQuery = ""; -// QuerySolutionMap initialBinding = new QuerySolutionMap(); -// Resource searchConfig = ResourceFactory.createResource(uri); -// -// initialBinding.add("searchConfig", searchConfig); -// -// Query query = QueryFactory.create(queryForEducationalTraining); -// displayOntModel.enterCriticalSection(Lock.READ); -// try{ -// QueryExecution qExec = QueryExecutionFactory.create(query, displayOntModel, initialBinding); -// try{ -// ResultSet results = qExec.execSelect(); -// while(results.hasNext()){ -// QuerySolution soln = results.nextSolution(); -// Literal node = soln.getLiteral("query"); -// if(node.isLiteral()){ -// resultQuery = node.toString(); -// }else{ -// log.warn("unexpected literal in the object position for context node queries " + node.toString()); -// } -// } -// }catch(Throwable t){ -// log.error(t,t); -// } finally{ -// qExec.close(); -// } -// }finally{ -// displayOntModel.leaveCriticalSection(); -// } -// -// return resultQuery.substring(0, resultQuery.length() - 3); -// } - - -// public List getFieldValues(String uri, Model modelToQuery, List queries){ - - //what do the queries need to be like? - // SELECT ?field ?value WHERE .... - - // what to do with multiple values for a field? - -// } - - - - //in different object: - /* - * get queries from somewhere - * get model to run queries on - * get list of individuals - * for each individual: - * fields = getFieldValues(uri, model, queiries) - * index(fields)? - * - * - */ - - public String getPropertiesAssociatedWithPosition(String uri){ - - StringBuffer propertyValues = new StringBuffer(); - - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - String thisQuery = prefix + - "SELECT " + - "(str(?HRJobTitle) as ?hrJobTitle) (str(?InvolvedOrganizationName) as ?involvedOrganizationName) " + - " (str(?PositionForPerson) as ?positionForPerson) (str(?PositionInOrganization) as ?positionInOrganization) " + - " (str(?TitleOrRole) as ?titleOrRole) WHERE {" //(str(?PositionLabel) as ?positionLabel) - - + "?uri rdf:type foaf:Agent ; ?b ?c . " - + " ?c rdf:type core:Position . " - - + " OPTIONAL { ?c core:hrJobTitle ?HRJobTitle . } . " - + " OPTIONAL { ?c core:involvedOrganizationName ?InvolvedOrganizationName . } ." - + " OPTIONAL { ?c core:positionForPerson ?f . ?f rdfs:label ?PositionForPerson . } . " - + " OPTIONAL { ?c core:positionInOrganization ?i . ?i rdfs:label ?PositionInOrganization . } . " - + " OPTIONAL { ?c core:titleOrRole ?TitleOrRole . } . " - //+ " OPTIONAL { ?c rdfs:label ?PositionLabel . } " - - + " } ORDER BY ?PositionLabel "; - - Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ); - fullModel.enterCriticalSection(Lock.READ); - - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding); - try{ - - ResultSet results = qExec.execSelect(); - - while(results.hasNext()){ - - QuerySolution soln = results.nextSolution(); - - RDFNode hrJobTitle = soln.get("hrJobTitle"); - if(hrJobTitle != null){ - propertyValues.append(" " + hrJobTitle.toString()); - }else{ - log.debug("hrJobTitle is null "); - } - - RDFNode involvedOrganizationName = soln.get("involvedOrganizationName"); - if(involvedOrganizationName != null){ - propertyValues.append(" " + involvedOrganizationName.toString()); - }else{ - log.debug("involvedOrganizationName is null "); - } - - RDFNode positionForPerson = soln.get("positionForPerson"); - if(positionForPerson != null){ - propertyValues.append(" " + positionForPerson.toString()); - }else{ - log.debug("positionForPerson is null "); - } - - RDFNode positionInOrganization = soln.get("positionInOrganization"); - if(positionInOrganization != null){ - propertyValues.append(" " + positionInOrganization.toString()); - }else{ - log.debug("positionInOrganization is null "); - } - - RDFNode titleOrRole = soln.get("titleOrRole"); - if(titleOrRole != null){ - propertyValues.append(" " + titleOrRole.toString()); - }else{ - log.debug("titleOrRole is null "); - } - - /*RDFNode positionLabel = soln.get("positionLabel"); - if(positionLabel != null){ - propertyValues.append(" " + positionLabel.toString()); - }else{ - log.debug("positionLabel is null "); - }*/ - - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - fullModel.leaveCriticalSection(); - } - - return propertyValues.toString(); - } - - public String getPropertiesAssociatedWithRelationship(String uri){ - - StringBuffer propertyValues = new StringBuffer(); - - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - String thisQuery = prefix + - "SELECT (str(?Advisee) as ?advisee) (str(?DegreeCandidacy) as ?degreeCandidacy) " + - " (str(?LinkedAuthor) as ?linkedAuthor) (str(?LinkedInformationResource) as ?linkedInformationResource) WHERE {" - - + "?uri rdf:type foaf:Agent ; ?b ?c . " - + " ?c rdf:type core:Relationship . " - - + " OPTIONAL { ?c core:advisee ?d . ?d rdfs:label ?Advisee . } . " - + " OPTIONAL { ?c core:degreeCandidacy ?e . ?e rdfs:label ?DegreeCandidacy . } ." - + " OPTIONAL { ?c core:linkedAuthor ?f . ?f rdfs:label ?LinkedAuthor . } . " - + " OPTIONAL { ?c core:linkedInformationResource ?h . ?h rdfs:label ?LinkedInformationResource . } . " - - + " } "; - - Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ); - fullModel.enterCriticalSection(Lock.READ); - - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding); - try{ - - ResultSet results = qExec.execSelect(); - - while(results.hasNext()){ - - QuerySolution soln = results.nextSolution(); - - RDFNode advisee = soln.get("advisee"); - if(advisee != null){ - propertyValues.append(" " + advisee.toString()); - }else{ - log.debug("advisee is null "); - } - - RDFNode degreeCandidacy = soln.get("degreeCandidacy"); - if(degreeCandidacy != null){ - propertyValues.append(" " + degreeCandidacy.toString()); - }else{ - log.debug("degreeCandidacy is null "); - } - - RDFNode linkedAuthor = soln.get("linkedAuthor"); - if(linkedAuthor != null){ - propertyValues.append(" " + linkedAuthor.toString()); - }else{ - log.debug("linkedAuthor is null "); - } - - RDFNode linkedInformationResource = soln.get("linkedInformationResource"); - if(linkedInformationResource != null){ - propertyValues.append(" " + linkedInformationResource.toString()); - }else{ - log.debug("linkedInformationResource is null "); - } - - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - fullModel.leaveCriticalSection(); - } - - return propertyValues.toString(); - } - - public String getPropertiesAssociatedWithAwardReceipt(String uri){ - - StringBuffer propertyValues = new StringBuffer(); - - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - String thisQuery = prefix + - "SELECT (str(?AwardConferredBy) as ?awardConferredBy) (str(?AwardOrHonorFor) as ?awardOrHonorFor) " + - " (str(?Description) as ?description) WHERE {" //(str(?AwardReceiptLabel) as ?awardReceiptLabel) - - + "?uri rdf:type foaf:Agent ; ?b ?c . " - + " ?c rdf:type core:AwardReceipt . " - - + " OPTIONAL { ?c core:awardConferredBy ?d . ?d rdfs:label ?AwardConferredBy } . " - + " OPTIONAL { ?c core:awardOrHonorFor ?e . ?e rdfs:label ?AwardOrHonorFor } ." - + " OPTIONAL { ?c core:description ?Description . } . " - //+ " OPTIONAL { ?c rdfs:label ?AwardReceiptLabel . } . " - - + " } ORDER BY ?AwardReceiptLabel"; - - Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ); - fullModel.enterCriticalSection(Lock.READ); - - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding); - try{ - - ResultSet results = qExec.execSelect(); - - while(results.hasNext()){ - - QuerySolution soln = results.nextSolution(); - - RDFNode awardConferredBy = soln.get("awardConferredBy"); - if(awardConferredBy != null){ - propertyValues.append(" " + awardConferredBy.toString()); - }else{ - log.debug("awardConferredBy is null "); - } - - RDFNode awardOrHonorFor = soln.get("awardOrHonorFor"); - if(awardOrHonorFor != null){ - propertyValues.append(" " + awardOrHonorFor.toString()); - }else{ - log.debug("awardOrHonorFor is null "); - } - - RDFNode description = soln.get("description"); - if(description != null){ - propertyValues.append(" " + description.toString()); - }else{ - log.debug("description is null "); - } - - /*RDFNode awardReceiptLabel = soln.get("awardReceiptLabel"); - if(awardReceiptLabel != null){ - propertyValues.append(" " + awardReceiptLabel.toString()); - }else{ - log.debug("awardReceiptLabel is null "); - }*/ - - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - fullModel.leaveCriticalSection(); - } - - return propertyValues.toString(); - } - - public String getPropertiesAssociatedWithRole(String uri){ - - StringBuffer propertyValues = new StringBuffer(); - - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - String thisQuery = prefix + - "SELECT DISTINCT (str(?OrganizationLabel) as ?organizationLabel) WHERE {" - + "?uri rdf:type foaf:Agent ; ?b ?c . " - + " ?c rdf:type core:Role ; core:roleIn ?Organization ." - + " ?Organization rdfs:label ?OrganizationLabel . " - + " } ORDER BY ?OrganizationLabel "; - - Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ); - fullModel.enterCriticalSection(Lock.READ); - - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding); - try{ - - ResultSet results = qExec.execSelect(); - - while(results.hasNext()){ - - QuerySolution soln = results.nextSolution(); - - RDFNode organizationLabel = soln.get("organizationLabel"); - if(organizationLabel != null){ - propertyValues.append(" " + organizationLabel.toString()); - }else{ - log.warn("organizationLabel is null "); - } - - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - fullModel.leaveCriticalSection(); - } - - return propertyValues.toString(); - } - - public String getPropertiesAssociatedWithEducationalTraining(String uri){ - - StringBuffer propertyValues = new StringBuffer(); - - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - String thisQuery = prefix + - "SELECT (str(?AcademicDegreeLabel) as ?academicDegreeLabel) (str(?AcademicDegreeAbbreviation) as ?academicDegreeAbbreviation) " - + "(str(?MajorField) as ?majorField) (str(?DepartmentOrSchool) as ?departmentOrSchool) " + - "(str(?TrainingAtOrganizationLabel) as ?trainingAtOrganizationLabel) WHERE {" - - + " ?uri rdf:type foaf:Agent ; ?b ?c . " - + " ?c rdf:type core:EducationalTraining . " - - + "OPTIONAL { ?c core:degreeEarned ?d . ?d rdfs:label ?AcademicDegreeLabel ; core:abbreviation ?AcademicDegreeAbbreviation . } . " - + "OPTIONAL { ?c core:majorField ?MajorField .} ." - + " OPTIONAL { ?c core:departmentOrSchool ?DepartmentOrSchool . }" - + " OPTIONAL { ?c core:trainingAtOrganization ?e . ?e rdfs:label ?TrainingAtOrganizationLabel . } . " - - +"}"; - - Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ); - fullModel.enterCriticalSection(Lock.READ); - - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding); - try{ - - ResultSet results = qExec.execSelect(); - - while(results.hasNext()){ - - QuerySolution soln = results.nextSolution(); - - RDFNode academicDegreeLabel = soln.get("academicDegreeLabel"); - if(academicDegreeLabel != null){ - propertyValues.append(" " + academicDegreeLabel.toString()); - }else{ - log.debug("academicDegreeLabel is null "); - } - - RDFNode academicDegreeAbbreviation = soln.get("academicDegreeAbbreviation"); - if(academicDegreeAbbreviation != null){ - propertyValues.append(" " + academicDegreeAbbreviation.toString()); - }else{ - log.debug("academicDegreeAbbreviation is null "); - } - - RDFNode majorField = soln.get("majorField"); - if(majorField != null){ - propertyValues.append(" " + majorField.toString()); - }else{ - log.debug("majorField is null "); - } - - RDFNode trainingAtDepartmentOrSchool = soln.get("departmentOrSchool"); - if(trainingAtDepartmentOrSchool != null){ - propertyValues.append(" " + trainingAtDepartmentOrSchool.toString()); - }else{ - log.debug("trainingAtDepartmentOrSchool is null "); - } - - RDFNode trainingAtOrganizationLabel = soln.get("trainingAtOrganizationLabel"); - if(trainingAtOrganizationLabel != null){ - propertyValues.append(" " + trainingAtOrganizationLabel.toString()); - }else{ - log.debug("trainingAtOrganizationLabel is null "); - } - - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - fullModel.leaveCriticalSection(); - } - return propertyValues.toString(); - - } - - public String getPropertiesAssociatedWithInformationResource(String uri){ - - StringBuffer propertyValues = new StringBuffer(); - - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - String thisQuery = prefix + - "SELECT (str(?LinkedAuthor) as ?linkedAuthor) (str(?LinkedInformationResource) as ?linkedInformationResource) " - + "(str(?Editor) as ?editor) (str(?SubjectArea) as ?subjectArea) (str(?ResearchAreaOf) as ?researchAreaOf) " + - "(str(?Features) as ?features) WHERE {" - - + " ?uri rdf:type core:InformationResource . " - - + "OPTIONAL { ?uri core:informationResourceInAuthorship ?a . ?a core:linkedAuthor ?b ; core:linkedInformationResource ?d ." + - "?b rdfs:label ?LinkedAuthor . ?d rdfs:label ?LinkedInformationResource } . " - + "OPTIONAL { ?uri bibo:editor ?e . ?e rdfs:label ?Editor . } ." - + " OPTIONAL { ?uri core:hasSubjectArea ?f . ?f rdfs:label ?SubjectArea ; core:researchAreaOf ?h . ?h rdfs:label ?ResearchAreaOf . } " - + " OPTIONAL { ?uri core:features ?i . ?i rdfs:label ?Features . } . " - - +"}"; - - Query sparqlQuery = QueryFactory.create(thisQuery, Syntax.syntaxARQ); - fullModel.enterCriticalSection(Lock.READ); - - try{ - QueryExecution qExec = QueryExecutionFactory.create(sparqlQuery, fullModel, initialBinding); - try{ - - ResultSet results = qExec.execSelect(); - - while(results.hasNext()){ - - QuerySolution soln = results.nextSolution(); - - RDFNode linkedAuthor = soln.get("linkedAuthor"); - if(linkedAuthor != null){ - propertyValues.append(" publications " + linkedAuthor.toString() + " publications "); - }else{ - log.debug("linkedAuthor is null "); - } - - RDFNode linkedInformationResource = soln.get("linkedInformationResource"); - if(linkedInformationResource != null){ - propertyValues.append(" " + linkedInformationResource.toString()); - }else{ - log.debug("linkedInformationResource is null "); - } - - RDFNode editor = soln.get("editor"); - if(editor != null){ - propertyValues.append(" " + editor.toString()); - }else{ - log.debug("editor is null "); - } - - RDFNode subjectArea = soln.get("subjectArea"); - if(subjectArea != null){ - propertyValues.append(" " + subjectArea.toString()); - }else{ - log.debug("subjectArea is null "); - } - - RDFNode researchAreaOf = soln.get("researchAreaOf"); - if(researchAreaOf != null){ - propertyValues.append(" " + researchAreaOf.toString()); - }else{ - log.debug("researchAreaOf is null "); - } - - RDFNode features = soln.get("features"); - if(features != null){ - propertyValues.append(" publications " + features.toString() + " publications "); - }else{ - log.debug("features is null "); - } - - } - }catch(Throwable t){ - log.error(t,t); - } finally{ - qExec.close(); - } - }finally{ - fullModel.leaveCriticalSection(); - } - return propertyValues.toString(); - - } - - public String[] getAdjacentNodes(String uri,boolean isPerson){ - - List queryList = new ArrayList(); - Set adjacentNodes = new HashSet(); - Set coauthorNames = new HashSet(); - String[] info = new String[]{"",""}; - StringBuffer adjacentNodesConcat = new StringBuffer(); - StringBuffer coauthorBuff = new StringBuffer(); - adjacentNodesConcat.append(""); - coauthorBuff.append(""); - - queryList.add(prefix + - " SELECT ?adjobj (str(?adjobjLabel) as ?coauthor) " + - " WHERE { " + - " ?uri rdf:type . " + - " ?uri ?prop ?obj . " + - " ?obj rdf:type . " + - " ?obj ?prop2 ?obj2 . " + - " ?obj2 rdf:type . " + - " ?obj2 ?prop3 ?obj3 . " + - " ?obj3 rdf:type . " + - " ?obj3 ?prop4 ?adjobj . " + - " ?adjobj rdfs:label ?adjobjLabel . " + - " ?adjobj rdf:type . " + - - " FILTER (?prop !=rdf:type) . " + - " FILTER (?prop2!=rdf:type) . " + - " FILTER (?prop3!=rdf:type) . " + - " FILTER (?prop4!=rdf:type) . " + - " FILTER (?adjobj != ?uri) . " + - "}"); - - queryList.add(prefix + - " SELECT ?adjobj " + - " WHERE{ " + - - " ?uri rdf:type foaf:Agent . " + - " ?uri ?prop ?obj . " + - " ?obj ?prop2 ?adjobj . " + - - - " FILTER (?prop !=rdf:type) . " + - " FILTER isURI(?obj) . " + - - " FILTER (?prop2!=rdf:type) . " + - " FILTER (?adjobj != ?uri) . " + - " FILTER isURI(?adjobj) . " + - - " { ?adjobj rdf:type . } " + - " UNION " + - " { ?adjobj rdf:type . } " + - " UNION " + - " { ?adjobj rdf:type . } " + - " UNION " + - " { ?adjobj rdf:type . } ." + - "}"); - - Query query; - - QuerySolution soln; - QuerySolutionMap initialBinding = new QuerySolutionMap(); - Resource uriResource = ResourceFactory.createResource(uri); - - initialBinding.add("uri", uriResource); - - Iterator queryItr = queryList.iterator(); - - fullModel.enterCriticalSection(Lock.READ); - Resource adjacentIndividual = null; - RDFNode coauthor = null; - try{ - while(queryItr.hasNext()){ - if(!isPerson){ - queryItr.next(); // we don't want first query to execute if the ind is not a person. - } - query = QueryFactory.create(queryItr.next(),Syntax.syntaxARQ); - QueryExecution qexec = QueryExecutionFactory.create(query,fullModel,initialBinding); - try{ - ResultSet results = qexec.execSelect(); - while(results.hasNext()){ - soln = results.nextSolution(); - - adjacentIndividual = (Resource)soln.get("adjobj"); - if(adjacentIndividual!=null){ - adjacentNodes.add(adjacentIndividual.getURI()); - } - - coauthor = soln.get("coauthor"); - if(coauthor!=null){ - coauthorNames.add(" co-authors " + coauthor.toString() + " co-authors "); - } - } - }catch(Exception e){ - log.error("Error found in getAdjacentNodes method of SearchQueryHandler"); - }finally{ - qexec.close(); - } - } - queryList = null; - Iterator itr = adjacentNodes.iterator(); - while(itr.hasNext()){ - adjacentNodesConcat.append(itr.next() + " "); - } - - info[0] = adjacentNodesConcat.toString(); - - itr = coauthorNames.iterator(); - while(itr.hasNext()){ - coauthorBuff.append(itr.next()); - } - - info[1] = coauthorBuff.toString(); - - } - catch(Throwable t){ - log.error(t,t); - }finally{ - fullModel.leaveCriticalSection(); - adjacentNodes = null; - adjacentNodesConcat = null; - coauthorBuff = null; - } - return info; - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java index 662ed4d16..b315e0902 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/Entity2LuceneDoc.java @@ -23,7 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; -import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler; + import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface; @@ -113,8 +113,6 @@ public class Entity2LuceneDoc implements Obj2DocIface{ private ProhibitedFromSearch classesProhibitedFromSearch; private IndividualProhibitedFromSearch individualProhibited; - - private SearchQueryHandler searchQueryHandler; private static HashMap IndividualURIToObjectProperties = new HashMap(); @@ -122,10 +120,9 @@ public class Entity2LuceneDoc implements Obj2DocIface{ public Entity2LuceneDoc( ProhibitedFromSearch classesProhibitedFromSearch, - IndividualProhibitedFromSearch individualProhibited, SearchQueryHandler searchQueryHandler){ + IndividualProhibitedFromSearch individualProhibited){ this.classesProhibitedFromSearch = classesProhibitedFromSearch; this.individualProhibited = individualProhibited; - this.searchQueryHandler = searchQueryHandler; } public boolean canTranslate(Object obj) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java index 08162714c..398a7c4c0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetup.java @@ -42,7 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; -import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler; + import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; @@ -119,8 +119,7 @@ public class LuceneSetup implements javax.servlet.ServletContextListener { OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel"); Entity2LuceneDoc translator = new Entity2LuceneDoc( new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel), - new IndividualProhibitedFromSearch(context), - new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context) + new IndividualProhibitedFromSearch(context) ); indexer.addObj2Doc(translator); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetupCJK.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetupCJK.java index 83dc5076a..fbc6f783c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetupCJK.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/lucene/LuceneSetupCJK.java @@ -27,7 +27,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; -import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler; import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; @@ -93,8 +92,8 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener { OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel"); Entity2LuceneDoc translator = new Entity2LuceneDoc( new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel), - new IndividualProhibitedFromSearch(context), - new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context)); + new IndividualProhibitedFromSearch(context) + ); indexer.addObj2Doc(translator); indexer.setLuceneIndexFactory(lif); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java index 7c98aee91..99d96955f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/CalculateParameters.java @@ -33,7 +33,7 @@ import com.hp.hpl.jena.ontology.OntModel; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames; -import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler; + public class CalculateParameters implements DocumentModifier { @@ -270,8 +270,11 @@ public class CalculateParameters implements DocumentModifier { for(String term: fieldsToMultiplyBetaBy){ SolrInputField f = doc.getField( term ); - f.setBoost( getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); + f.addValue(info.toString(),getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); } + + SolrInputField f = doc.getField(VitroTermNames.targetInfo); + f.addValue(adjInfo[1],f.getBoost()); doc.setDocumentBoost(getBeta(uri)*phi*IndividualToSolrDocument.ALL_TEXT_BOOST); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java index 3711f1a02..dd52bd6ae 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ContextNodeFields.java @@ -24,6 +24,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.shared.Lock; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames; import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames; public class ContextNodeFields implements DocumentModifier{ @@ -49,22 +50,25 @@ public class ContextNodeFields implements DocumentModifier{ @Override public void modifyDocument(Individual individual, SolrInputDocument doc) { - SolrInputField field = doc.getField(VitroLuceneTermNames.ALLTEXT); + SolrInputField field = doc.getField(VitroTermNames.ALLTEXT); + SolrInputField targetField = doc.getField(VitroTermNames.targetInfo); StringBuffer objectProperties = new StringBuffer(); - - objectProperties.append(" "); - objectProperties.append(getPropertiesAssociatedWithEducationalTraining(individual.getURI())); - objectProperties.append(" "); - objectProperties.append(getPropertiesAssociatedWithRole(individual.getURI())); - objectProperties.append(" "); - objectProperties.append(getPropertiesAssociatedWithPosition(individual.getURI())); - objectProperties.append(" "); - objectProperties.append(getPropertiesAssociatedWithRelationship(individual.getURI())); - objectProperties.append(" "); - objectProperties.append(getPropertiesAssociatedWithAwardReceipt(individual.getURI())); - objectProperties.append(" "); - objectProperties.append(getPropertiesAssociatedWithInformationResource(individual.getURI())); - + + if(IndividualToSolrDocument.superClassNames.contains("Agent")){ + objectProperties.append(" "); + objectProperties.append(getPropertiesAssociatedWithEducationalTraining(individual.getURI())); + objectProperties.append(" "); + objectProperties.append(getPropertiesAssociatedWithRole(individual.getURI())); + objectProperties.append(" "); + objectProperties.append(getPropertiesAssociatedWithPosition(individual.getURI())); + objectProperties.append(" "); + objectProperties.append(getPropertiesAssociatedWithRelationship(individual.getURI())); + objectProperties.append(" "); + objectProperties.append(getPropertiesAssociatedWithAwardReceipt(individual.getURI())); + } + if(IndividualToSolrDocument.superClassNames.contains("InformationResource")){ + targetField.addValue(" " + getPropertiesAssociatedWithInformationResource(individual.getURI()), targetField.getBoost()); + } field.addValue(objectProperties, field.getBoost()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java index a52dc14f6..70c7aae10 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/IndividualToSolrDocument.java @@ -32,7 +32,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames; -import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler; import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface; @@ -51,8 +50,6 @@ public class IndividualToSolrDocument implements Obj2DocIface { private IndividualProhibitedFromSearch individualProhibitedFromSearch; - private SearchQueryHandler searchQueryHandler; - public static ArrayList superClassNames = null; public static StringBuffer addUri = null; @@ -62,19 +59,16 @@ public class IndividualToSolrDocument implements Obj2DocIface { private static List contextNodeClassNames = new ArrayList(); public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch, - IndividualProhibitedFromSearch individualProhibitedFromSearch, - SearchQueryHandler searchQueryHandler){ - this(classesProhibitedFromSearch,individualProhibitedFromSearch,searchQueryHandler,null); + IndividualProhibitedFromSearch individualProhibitedFromSearch){ + this(classesProhibitedFromSearch,individualProhibitedFromSearch,null); } public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch, IndividualProhibitedFromSearch individualProhibitedFromSearch, - SearchQueryHandler searchQueryHandler, List docModifiers){ this.classesProhibitedFromSearch = classesProhibitedFromSearch; this.individualProhibitedFromSearch = individualProhibitedFromSearch; this.documentModifiers = docModifiers; - this.searchQueryHandler = searchQueryHandler; fillContextNodes(); } @@ -230,10 +224,9 @@ public class IndividualToSolrDocument implements Obj2DocIface { // collecting context node information - StringBuffer targetInfo = new StringBuffer(); - targetInfo.append(""); - doc.addField(term.targetInfo, targetInfo.toString() + adjInfo[1]); + + log.debug("time to fire contextnode queries and include them in the index: " + Long.toString(System.currentTimeMillis() - tContextNodes)); @@ -298,6 +291,7 @@ public class IndividualToSolrDocument implements Obj2DocIface { //run the document modifiers if( documentModifiers != null ){ + doc.addField(term.targetInfo,""); for(DocumentModifier modifier: documentModifiers){ modifier.modifyDocument(ent, doc); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java index 612a8d4e3..4f5f48d74 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrIndexer.java @@ -136,8 +136,8 @@ public class SolrIndexer implements IndexerIface { } catch (Exception e) { log.error("Could not commit to solr server", e); }finally{ - IndividualToSolrDocument.betas.clear(); - IndividualToSolrDocument.betas = null; + CalculateParameters.betaMap.clear(); + CalculateParameters.betaMap = null; } try { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java index 3bb6524ec..960ae739c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java @@ -23,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; -import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler; import edu.cornell.mannlib.vitro.webapp.search.beans.IndividualProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; @@ -70,15 +69,12 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ OntModel displayOntModel = (OntModel) sce.getServletContext().getAttribute("displayOntModel"); List modifiers = new ArrayList(); - CalculateBeta betas = new CalculateBeta(ModelContext.getJenaOntModel(context)); - modifiers.add( new CalculateBeta(ModelContext.getJenaOntModel(context))); - modifiers.add( new CalculatePhi(betas)); - modifiers.add( new ContextNodeFields() ); + modifiers.add(new CalculateParameters(ModelContext.getJenaOntModel(context))); + modifiers.add(new ContextNodeFields(ModelContext.getJenaOntModel(context))); IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument( new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel), new IndividualProhibitedFromSearch(context), - new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context), modifiers); List o2d = new ArrayList(); o2d.add(indToSolrDoc);