Adding DocumentModifier interface.
This commit is contained in:
parent
3c6a60818e
commit
eb4aeef8d1
5 changed files with 89 additions and 1 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.search.solr;
|
||||||
|
|
||||||
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
|
||||||
|
public class CalculateBeta implements DocumentModifier{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modifyDocument(Individual individual, SolrInputDocument doc) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
/*
|
||||||
|
may want to do something like:
|
||||||
|
|
||||||
|
Field f = doc.getField(termALLTEXTUSTEMMED);
|
||||||
|
f.setBoost( beta * f.getBoost() )
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.search.solr;
|
||||||
|
|
||||||
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
|
||||||
|
public class CalculatePhi implements DocumentModifier{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modifyDocument(Individual individual, SolrInputDocument doc) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.search.solr;
|
||||||
|
|
||||||
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
|
||||||
|
public class ContextNodeFields implements DocumentModifier{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modifyDocument(Individual individual, SolrInputDocument doc) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.search.solr;
|
||||||
|
|
||||||
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface represents an object that can add to a SolrInputDocument.
|
||||||
|
*/
|
||||||
|
public interface DocumentModifier {
|
||||||
|
public void modifyDocument(Individual individual, SolrInputDocument doc);
|
||||||
|
}
|
|
@ -52,6 +52,8 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
||||||
private IndividualProhibitedFromSearch individualProhibitedFromSearch;
|
private IndividualProhibitedFromSearch individualProhibitedFromSearch;
|
||||||
|
|
||||||
private SearchQueryHandler searchQueryHandler;
|
private SearchQueryHandler searchQueryHandler;
|
||||||
|
|
||||||
|
private List<DocumentModifier> documentModifiers = new ArrayList<DocumentModifier>();
|
||||||
|
|
||||||
public static Map<String,Float> betas = new Hashtable<String,Float>();
|
public static Map<String,Float> betas = new Hashtable<String,Float>();
|
||||||
|
|
||||||
|
@ -66,7 +68,15 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
||||||
fillContextNodes();
|
fillContextNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch,
|
||||||
|
IndividualProhibitedFromSearch individualProhibitedFromSearch,
|
||||||
|
List<DocumentModifier> docModifiers){
|
||||||
|
this.classesProhibitedFromSearch = classesProhibitedFromSearch;
|
||||||
|
this.individualProhibitedFromSearch = individualProhibitedFromSearch;
|
||||||
|
this.documentModifiers = docModifiers;
|
||||||
|
fillContextNodes();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
@Override
|
@Override
|
||||||
public Object translate(Object obj) throws IndexingException{
|
public Object translate(Object obj) throws IndexingException{
|
||||||
|
@ -317,6 +327,13 @@ public class IndividualToSolrDocument implements Obj2DocIface {
|
||||||
doc.addField(term.ALLTEXTUNSTEMMED, alltext, 2.5F*beta*phi);
|
doc.addField(term.ALLTEXTUNSTEMMED, alltext, 2.5F*beta*phi);
|
||||||
doc.addField(term.ALLTEXT_PHONETIC, alltext, PHONETIC_BOOST);
|
doc.addField(term.ALLTEXT_PHONETIC, alltext, PHONETIC_BOOST);
|
||||||
doc.setDocumentBoost(2.5F*beta*phi);
|
doc.setDocumentBoost(2.5F*beta*phi);
|
||||||
|
|
||||||
|
//run the document modifiers
|
||||||
|
if( documentModifiers != null ){
|
||||||
|
for(DocumentModifier modifier: documentModifiers){
|
||||||
|
modifier.modifyDocument(ent, doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue