NIHVIVO-352 Applied Miles' patch for search snippets.
This commit is contained in:
parent
d434376bdc
commit
8095541706
10 changed files with 53 additions and 9 deletions
|
@ -564,7 +564,7 @@
|
|||
<field name="indexedTime" type="long" indexed="true" stored="true"/>
|
||||
<field name="NAME_PHONETIC" type ="phonetic" indexed="true" stored="false" multiValued="true"/>
|
||||
|
||||
<field name="ALLTEXT" type="text" indexed="true" stored="false" multiValued="true"/>
|
||||
<field name="ALLTEXT" type="text" indexed="true" stored="true" multiValued="true"/>
|
||||
<field name="ALLTEXTUNSTEMMED" type="textgen" indexed="true" stored="false" multiValued="true"/>
|
||||
<field name="ALLTEXT_PHONETIC" type="phonetic" indexed="true" stored="false" multiValued="true"/>
|
||||
|
||||
|
|
|
@ -714,6 +714,11 @@
|
|||
<int name="rows">10</int>
|
||||
<str name="q.alt">*:*</str>
|
||||
<str name="fl">*,score</str>
|
||||
<str name="hl">true</str>
|
||||
<str name="hl.fl">ALLTEXT</str>
|
||||
<str name="hl.fragsize">160</str>
|
||||
<str name="hl.simple.pre"><![CDATA[<strong>]]></str>
|
||||
<str name="hl.simple.post"><![CDATA[</strong>]]></str>
|
||||
</lst>
|
||||
<!-- In addition to defaults, "appends" params can be specified
|
||||
to identify values which should be appended to the list of
|
||||
|
|
BIN
webapp/lib/jsoup-1.6.1.jar
Normal file
BIN
webapp/lib/jsoup-1.6.1.jar
Normal file
Binary file not shown.
|
@ -98,4 +98,7 @@ public interface Individual extends ResourceBean, Comparable<Individual> {
|
|||
|
||||
Float getSearchBoost();
|
||||
void setSearchBoost( Float boost );
|
||||
|
||||
String getSearchSnippet();
|
||||
void setSearchSnippet( String snippet );
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
|
|||
protected String mainImageUri = NOT_INITIALIZED;
|
||||
protected ImageInfo imageInfo = null;
|
||||
protected Float searchBoost;
|
||||
protected String searchSnippet;
|
||||
|
||||
/** indicates if sortForDisplay has been called */
|
||||
protected boolean sorted = false;
|
||||
|
@ -277,6 +278,9 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
|
|||
public Float getSearchBoost() { return searchBoost; }
|
||||
public void setSearchBoost(Float boost) { searchBoost = boost; }
|
||||
|
||||
public String getSearchSnippet() { return searchSnippet; }
|
||||
public void setSearchSnippet(String snippet) { searchSnippet = snippet; }
|
||||
|
||||
/**
|
||||
* Sorts the ents2ents records into the proper order for display.
|
||||
*
|
||||
|
|
|
@ -448,6 +448,11 @@ public class IndividualFiltering implements Individual {
|
|||
public void setSearchBoost(Float boost) { _innerIndividual.setSearchBoost( boost ); }
|
||||
@Override
|
||||
public Float getSearchBoost() {return _innerIndividual.getSearchBoost(); }
|
||||
|
||||
@Override
|
||||
public void setSearchSnippet(String snippet) { _innerIndividual.setSearchSnippet( snippet ); }
|
||||
@Override
|
||||
public String getSearchSnippet() {return _innerIndividual.getSearchSnippet(); }
|
||||
|
||||
@Override
|
||||
public List<String> getDataValues(String propertyUri) {
|
||||
|
|
|
@ -235,8 +235,10 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
Individual ent = new IndividualImpl();
|
||||
ent.setURI(uri);
|
||||
ent = iDao.getIndividualByURI(uri);
|
||||
if(ent!=null)
|
||||
individuals.add(ent);
|
||||
if(ent!=null) {
|
||||
ent.setSearchSnippet(getSnippet(doc, response));
|
||||
individuals.add(ent);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
log.error("Problem getting usable individuals from search hits. " +
|
||||
e.getMessage());
|
||||
|
@ -438,6 +440,19 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
}
|
||||
}
|
||||
return typesInHits;
|
||||
}
|
||||
|
||||
private String getSnippet(SolrDocument doc, QueryResponse response) {
|
||||
String docId = doc.get(VitroSearchTermNames.DOCID).toString();
|
||||
StringBuffer text = new StringBuffer("");
|
||||
if (response.getHighlighting() != null && response.getHighlighting().get(docId) != null) {
|
||||
List<String> snippets = response.getHighlighting().get(docId).get(VitroSearchTermNames.ALLTEXT);
|
||||
if (snippets != null && snippets.size() > 0) {
|
||||
text.append("... " + snippets.get(0) + " ...");
|
||||
}
|
||||
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
private SolrQuery getQuery(String queryText, int maxHitCount, VitroRequest vreq) {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.solr;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
@ -149,11 +151,6 @@ public class IndividualToSolrDocument {
|
|||
String t=null;
|
||||
//ALLTEXT, all of the 'full text'
|
||||
StringBuffer allTextValue = new StringBuffer();
|
||||
allTextValue.append("");
|
||||
allTextValue.append(" ");
|
||||
allTextValue.append(((t=ind.getName()) == null)?"":t);
|
||||
allTextValue.append(" ");
|
||||
allTextValue.append(classPublicNames);
|
||||
|
||||
//collecting data property statements
|
||||
List<DataPropertyStatement> dataPropertyStatements = ind.getDataPropertyStatements();
|
||||
|
@ -170,8 +167,17 @@ public class IndividualToSolrDocument {
|
|||
}
|
||||
|
||||
allTextValue.append(objectNames.toString());
|
||||
|
||||
try {
|
||||
String stripped = Jsoup.parse(allTextValue.toString()).text();
|
||||
allTextValue.setLength(0);
|
||||
allTextValue.append(stripped);
|
||||
} catch(Exception e) {
|
||||
log.debug("Could not strip HTML during search indexing. " + e);
|
||||
}
|
||||
|
||||
String alltext = allTextValue.toString();
|
||||
|
||||
doc.addField(term.ALLTEXT, alltext);
|
||||
doc.addField(term.ALLTEXTUNSTEMMED, alltext);
|
||||
doc.addField(term.ALLTEXT_PHONETIC, alltext);
|
||||
|
|
|
@ -63,4 +63,8 @@ public abstract class BaseIndividualSearchResult extends BaseTemplateModel {
|
|||
return getView(ClassView.SEARCH);
|
||||
}
|
||||
|
||||
public String getSnippet() {
|
||||
return individual.getSearchSnippet();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@
|
|||
|
||||
<a href="${individual.profileUrl}">${individual.name}</a>
|
||||
|
||||
<@p.mostSpecificTypes individual />
|
||||
<@p.mostSpecificTypes individual />
|
||||
|
||||
<p>${individual.snippet}</p>
|
Loading…
Add table
Add a link
Reference in a new issue