added dismax query parser, boost for alltext fields and changed name of ContextNodeFactory

This commit is contained in:
anupsawant 2011-05-23 19:46:14 +00:00
parent 51bb061156
commit cf69ec009a
9 changed files with 68 additions and 38 deletions

View file

@ -498,7 +498,7 @@
<field name="THUMBNAIL" type="string" indexed="true" stored="true"/> <field name="THUMBNAIL" type="string" indexed="true" stored="true"/>
<field name="contextNode" type="text" indexed="true" stored="true" multiValued="true"/> <field name="contextNode" type="text" indexed="true" stored="true" multiValued="true"/>
<field name="BETA" type="float" indexed="true" stored="true" multiValued="false"/>
<field name="moniker" type="ignored" /> <field name="moniker" type="ignored" />
<field name="modType" type="ignored"/> <field name="modType" type="ignored"/>
@ -573,7 +573,7 @@
<uniqueKey>DocId</uniqueKey> <uniqueKey>DocId</uniqueKey>
<!-- field for the QueryParser to use when an explicit fieldname is absent --> <!-- field for the QueryParser to use when an explicit fieldname is absent -->
<defaultSearchField>ALLTEXT</defaultSearchField> <!-- <defaultSearchField>ALLTEXT</defaultSearchField> -->
<!-- SolrQueryParser configuration: defaultOperator="AND|OR" --> <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="AND"/> <solrQueryParser defaultOperator="AND"/>

View file

@ -707,6 +707,8 @@
will be overridden by parameters in the request will be overridden by parameters in the request
--> -->
<lst name="defaults"> <lst name="defaults">
<str name="defType">dismax</str>
<str name="qf">nameRaw nameLowercase nameUnstemmed nameStemmed ALLTEXT ALLTEXTUNSTEMMED</str>
<str name="echoParams">explicit</str> <str name="echoParams">explicit</str>
<int name="rows">10</int> <int name="rows">10</int>
</lst> </lst>
@ -784,10 +786,12 @@
<str name="v.layout">layout</str> <str name="v.layout">layout</str>
<str name="title">Solritas</str> <str name="title">Solritas</str>
<str name="defType">edismax</str> <!-- <str name="defType">edismax</str> -->
<str name="q.alt">*:*</str> <str name="q.alt">*:*</str>
<str name="rows">10</str> <str name="rows">10</str>
<str name="fl">*,score</str> <str name="fl">*,score</str>
<str name="mlt.qf"> <str name="mlt.qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4 text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
</str> </str>

View file

@ -54,4 +54,7 @@ public class VitroTermNames {
/** rdfs:label lowercased, tokenized, stop words, stemmed **/ /** rdfs:label lowercased, tokenized, stop words, stemmed **/
public static String NAME_STEMMED = "nameStemmed"; // was NAME public static String NAME_STEMMED = "nameStemmed"; // was NAME
/** field for beta values of all documents **/
public static final String BETA = "BETA";
} }

View file

@ -15,15 +15,17 @@ import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Literal; 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.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; 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.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
public class ContextNodesInclusionFactory { public class SearchQueryHandler {
private OntModel fullModel; private OntModel fullModel;
private String contextNodeURI; private String contextNodeURI;
@ -32,9 +34,9 @@ public class ContextNodesInclusionFactory {
// private static final String queryForEducationalTraining = "SELECT ?query WHERE {" + // private static final String queryForEducationalTraining = "SELECT ?query WHERE {" +
// "?searchConfig <"+ DisplayVocabulary.QUERY_FOR_EDUCATIONAL_TRAINING + "> ?query . }"; // "?searchConfig <"+ DisplayVocabulary.QUERY_FOR_EDUCATIONAL_TRAINING + "> ?query . }";
private static Log log = LogFactory.getLog(ContextNodesInclusionFactory.class); private static Log log = LogFactory.getLog(SearchQueryHandler.class);
public ContextNodesInclusionFactory(String contextNodeURI, public SearchQueryHandler(String contextNodeURI,
OntModel displayOntModel, ServletContext context) { OntModel displayOntModel, ServletContext context) {
this.fullModel = ModelContext.getJenaOntModel(context); this.fullModel = ModelContext.getJenaOntModel(context);
this.contextNodeURI = contextNodeURI; this.contextNodeURI = contextNodeURI;
@ -643,6 +645,22 @@ public class ContextNodesInclusionFactory {
} }
private int getTotalIndividuals(){
return fullModel.listIndividuals().toList().size();
}
public float calculateBeta(String uri){
float beta=0;
RDFNode node = (Resource) fullModel.getResource(uri);
StmtIterator stmtItr = fullModel.listStatements((Resource)null, (Property)null,node);
int Conn = 0;
while(stmtItr.hasNext()){
stmtItr.next();
Conn++;
}
beta = (float)Conn/getTotalIndividuals();
beta += 1;
return beta;
}
} }

View file

@ -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.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.beans.ContextNodesInclusionFactory; 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.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface; import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
@ -110,7 +110,7 @@ public class Entity2LuceneDoc implements Obj2DocIface{
private IndividualProhibitedFromSearch individualProhibited; private IndividualProhibitedFromSearch individualProhibited;
private ContextNodesInclusionFactory contextNodesInclusionFactory; private SearchQueryHandler searchQueryHandler;
private static HashMap<String, String> IndividualURIToObjectProperties = new HashMap<String, String>(); private static HashMap<String, String> IndividualURIToObjectProperties = new HashMap<String, String>();
@ -118,10 +118,10 @@ public class Entity2LuceneDoc implements Obj2DocIface{
public Entity2LuceneDoc( public Entity2LuceneDoc(
ProhibitedFromSearch classesProhibitedFromSearch, ProhibitedFromSearch classesProhibitedFromSearch,
IndividualProhibitedFromSearch individualProhibited, ContextNodesInclusionFactory contextNodesInclusionFactory){ IndividualProhibitedFromSearch individualProhibited, SearchQueryHandler searchQueryHandler){
this.classesProhibitedFromSearch = classesProhibitedFromSearch; this.classesProhibitedFromSearch = classesProhibitedFromSearch;
this.individualProhibited = individualProhibited; this.individualProhibited = individualProhibited;
this.contextNodesInclusionFactory = contextNodesInclusionFactory; this.searchQueryHandler = searchQueryHandler;
} }
public boolean canTranslate(Object obj) { public boolean canTranslate(Object obj) {
@ -242,12 +242,12 @@ public class Entity2LuceneDoc implements Obj2DocIface{
String contextNodePropertyValues; String contextNodePropertyValues;
// if(ent.isVClass("http://xmlns.com/foaf/0.1/Person")){ // if(ent.isVClass("http://xmlns.com/foaf/0.1/Person")){
contextNodePropertyValues = contextNodesInclusionFactory.getPropertiesAssociatedWithEducationalTraining(ent.getURI()); contextNodePropertyValues = searchQueryHandler.getPropertiesAssociatedWithEducationalTraining(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithRole(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithRole(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithPosition(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithPosition(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithRelationship(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithRelationship(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithAwardReceipt(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithAwardReceipt(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithInformationResource(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithInformationResource(ent.getURI());
// } // }

View file

@ -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.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; 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.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ContextNodesInclusionFactory; import edu.cornell.mannlib.vitro.webapp.search.beans.SearchQueryHandler;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup; import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
@ -120,7 +120,7 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
Entity2LuceneDoc translator = new Entity2LuceneDoc( Entity2LuceneDoc translator = new Entity2LuceneDoc(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel), new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
new IndividualProhibitedFromSearch(context), new IndividualProhibitedFromSearch(context),
new ContextNodesInclusionFactory(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context) new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context)
); );
indexer.addObj2Doc(translator); indexer.addObj2Doc(translator);

View file

@ -27,7 +27,7 @@ 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.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.ContextNodesInclusionFactory; 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.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
@ -94,7 +94,7 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
Entity2LuceneDoc translator = new Entity2LuceneDoc( Entity2LuceneDoc translator = new Entity2LuceneDoc(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel), new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
new IndividualProhibitedFromSearch(context), new IndividualProhibitedFromSearch(context),
new ContextNodesInclusionFactory(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context)); new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context));
indexer.addObj2Doc(translator); indexer.addObj2Doc(translator);
indexer.setLuceneIndexFactory(lif); indexer.setLuceneIndexFactory(lif);

View file

@ -13,6 +13,10 @@ import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
import org.joda.time.DateTime; import org.joda.time.DateTime;
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.StmtIterator;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
@ -23,7 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames; import edu.cornell.mannlib.vitro.webapp.search.VitroTermNames;
import edu.cornell.mannlib.vitro.webapp.search.beans.ContextNodesInclusionFactory; 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.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface; import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
@ -42,16 +46,16 @@ public class IndividualToSolrDocument implements Obj2DocIface {
private IndividualProhibitedFromSearch individualProhibitedFromSearch; private IndividualProhibitedFromSearch individualProhibitedFromSearch;
private ContextNodesInclusionFactory contextNodesInclusionFactory; private SearchQueryHandler searchQueryHandler;
public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch, public IndividualToSolrDocument(ProhibitedFromSearch classesProhibitedFromSearch,
IndividualProhibitedFromSearch individualProhibitedFromSearch, IndividualProhibitedFromSearch individualProhibitedFromSearch,
ContextNodesInclusionFactory contextNodesInclusionFactory){ SearchQueryHandler searchQueryHandler){
this.classesProhibitedFromSearch = classesProhibitedFromSearch; this.classesProhibitedFromSearch = classesProhibitedFromSearch;
this.individualProhibitedFromSearch = individualProhibitedFromSearch; this.individualProhibitedFromSearch = individualProhibitedFromSearch;
this.contextNodesInclusionFactory = contextNodesInclusionFactory; this.searchQueryHandler = searchQueryHandler;
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
@ -156,12 +160,12 @@ public class IndividualToSolrDocument implements Obj2DocIface {
long tContextNodes = System.currentTimeMillis(); long tContextNodes = System.currentTimeMillis();
String contextNodePropertyValues = ""; String contextNodePropertyValues = "";
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithEducationalTraining(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithEducationalTraining(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithRole(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithRole(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithPosition(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithPosition(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithRelationship(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithRelationship(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithAwardReceipt(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithAwardReceipt(ent.getURI());
contextNodePropertyValues += contextNodesInclusionFactory.getPropertiesAssociatedWithInformationResource(ent.getURI()); contextNodePropertyValues += searchQueryHandler.getPropertiesAssociatedWithInformationResource(ent.getURI());
doc.addField(term.CONTEXTNODE, contextNodePropertyValues); doc.addField(term.CONTEXTNODE, contextNodePropertyValues);
@ -237,8 +241,8 @@ public class IndividualToSolrDocument implements Obj2DocIface {
log.debug("time to include data property statements, object property statements in the index: " + Long.toString(System.currentTimeMillis() - tPropertyStatements)); log.debug("time to include data property statements, object property statements in the index: " + Long.toString(System.currentTimeMillis() - tPropertyStatements));
doc.addField(term.ALLTEXT, value); doc.addField(term.ALLTEXT, value,ALL_TEXT_BOOST);
doc.addField(term.ALLTEXTUNSTEMMED, value); doc.addField(term.ALLTEXTUNSTEMMED, value,ALL_TEXT_BOOST);
} }
return doc; return doc;
@ -282,5 +286,6 @@ public class IndividualToSolrDocument implements Obj2DocIface {
} }
public static float NAME_BOOST = 3.0F; public static float NAME_BOOST = 3.0F;
public static float ALL_TEXT_BOOST = 2.0F;
} }

View file

@ -23,7 +23,7 @@ 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.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener; import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.ContextNodesInclusionFactory; 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.IndividualProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; 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.ProhibitedFromSearch;
@ -76,7 +76,7 @@ public class SolrSetup implements javax.servlet.ServletContextListener{
IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument( IndividualToSolrDocument indToSolrDoc = new IndividualToSolrDocument(
new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel), new ProhibitedFromSearch(DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel),
new IndividualProhibitedFromSearch(context), new IndividualProhibitedFromSearch(context),
new ContextNodesInclusionFactory(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context)); new SearchQueryHandler(DisplayVocabulary.CONTEXT_NODES_URI, displayOntModel, context));
List<Obj2DocIface> o2d = new ArrayList<Obj2DocIface>(); List<Obj2DocIface> o2d = new ArrayList<Obj2DocIface>();
o2d.add(indToSolrDoc); o2d.add(indToSolrDoc);