Avoid frequent data type casting (float/long) for rwi score

refactor to using long in URIMetadataNode too (and related call parameters)
As remote rwi score's are not used (since v1.83) skip reading float-score ,
but keep in toString() for communication with older versions.
pull/91/head
reger 9 years ago
parent 3ccd89e274
commit 685d8e86bf

@ -172,7 +172,7 @@ public class EnhancedXMLResponseWriter implements QueryResponseWriter {
startTagOpen(writer, "doc", name); startTagOpen(writer, "doc", name);
if (includeScore) { if (includeScore) {
writeTag(writer, "float", "score", Float.toString(score), false); writeTag(writer, "float", "score", Float.toString(score), false); // this is the special Solr "score" pseudo-field
} }
int sz = fields.size(); int sz = fields.size();

@ -81,7 +81,7 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
protected Bitfield flags = null; protected Bitfield flags = null;
protected int imagec = -1, audioc = -1, videoc = -1, appc = -1; protected int imagec = -1, audioc = -1, videoc = -1, appc = -1;
protected double lat = Double.NaN, lon = Double.NaN; protected double lat = Double.NaN, lon = Double.NaN;
protected float score = 0; // during generation of a search result this value is set protected long score = 0; // during generation of a search result this value is set
protected String snippet = null; protected String snippet = null;
protected WordReferenceVars word = null; // this is only used if the url is transported via remote search requests protected WordReferenceVars word = null; // this is only used if the url is transported via remote search requests
@ -151,7 +151,7 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
this.videoc = Integer.parseInt(prop.getProperty("lvideo", "0")); this.videoc = Integer.parseInt(prop.getProperty("lvideo", "0"));
this.appc = Integer.parseInt(prop.getProperty("lapp", "0")); this.appc = Integer.parseInt(prop.getProperty("lapp", "0"));
this.snippet = crypt.simpleDecode(prop.getProperty("snippet", "")); this.snippet = crypt.simpleDecode(prop.getProperty("snippet", ""));
this.score = Float.parseFloat(prop.getProperty("score", "0.0")); // we don't use the remote rwi ranking but the local rwi ranking profile // this.score = Float.parseFloat(prop.getProperty("score", "0.0")); // we don't use the remote rwi ranking but the local rwi ranking profile
List<String> cs = new ArrayList<String>(); List<String> cs = new ArrayList<String>();
cs.add(collection); cs.add(collection);
this.setField(CollectionSchema.collection_sxt.name(), cs); this.setField(CollectionSchema.collection_sxt.name(), cs);
@ -188,10 +188,16 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
} }
} }
public URIMetadataNode(final SolrDocument doc, final WordReferenceVars searchedWord, final float scorex) throws MalformedURLException { /**
* @param doc metadata from (embedded) Solr index
* @param searchedWord rwi WordReference the metadata belong to
* @param scorex rwi score
* @throws MalformedURLException
*/
public URIMetadataNode(final SolrDocument doc, final WordReferenceVars searchedWord, final long scorex) throws MalformedURLException {
this(doc); this(doc);
this.word = searchedWord; this.word = searchedWord; // rwi index WordReference this document (metadata) belong to
this.score = scorex; this.score = scorex; // rwi/YaCy score
} }
public URIMetadataNode(DigestURL theurl) { public URIMetadataNode(DigestURL theurl) {
@ -334,7 +340,7 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
* (the value is updated while adding to the result queue where score calc takes place) * (the value is updated while adding to the result queue where score calc takes place)
* @return YaCy calculated score (number > 0) * @return YaCy calculated score (number > 0)
*/ */
public float score() { public long score() {
return this.score; return this.score;
} }
@ -343,7 +349,7 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
* (should be set to the effective value of result queues getWeight) * (should be set to the effective value of result queues getWeight)
* @param theScore YaCy ranking of search results * @param theScore YaCy ranking of search results
*/ */
public void setScore(float theScore) { public void setScore(long theScore) {
this.score = theScore; this.score = theScore;
} }
@ -589,7 +595,7 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
s.append(",laudio=").append(this.laudio()); s.append(",laudio=").append(this.laudio());
s.append(",lvideo=").append(this.lvideo()); s.append(",lvideo=").append(this.lvideo());
s.append(",lapp=").append(this.lapp()); s.append(",lapp=").append(this.lapp());
s.append(",score=").append(Float.toString(this.score())); s.append(",score=").append(Long.toString(this.score()));
if (this.word() != null) { if (this.word() != null) {
// append also word properties // append also word properties
final String wprop = this.word().toPropertyForm(); final String wprop = this.word().toPropertyForm();

@ -286,21 +286,32 @@ public final class Fulltext {
if (this.writeWebgraph) getWebgraphConnector().commit(softCommit); if (this.writeWebgraph) getWebgraphConnector().commit(softCommit);
} }
/**
* Loads the meta data stored in the embedded solr index for the url referenced
* by the WordReference.
* The WordReference and the YaCy score (element.weight()) become part (and
* are accessible) of the returned document.
* If the no document with url.hash = solrdocument.id is found in the embedded
* Solr index null is return.
*
* @param element rwi wordreference
* @return URIMetadataNode (solrdocument) with all fields stored in embedded solr index
*/
public URIMetadataNode getMetadata(final WeakPriorityBlockingQueue.Element<WordReferenceVars> element) { public URIMetadataNode getMetadata(final WeakPriorityBlockingQueue.Element<WordReferenceVars> element) {
if (element == null) return null; if (element == null) return null;
WordReferenceVars wre = element.getElement(); WordReferenceVars wre = element.getElement();
if (wre == null) return null; // all time was already wasted in takeRWI to get another element if (wre == null) return null; // all time was already wasted in takeRWI to get another element
float score = element.getWeight(); long score = element.getWeight();
URIMetadataNode node = getMetadata(wre.urlhash(), wre, score); URIMetadataNode node = getMetadata(wre.urlhash(), wre, score);
return node; return node;
} }
public URIMetadataNode getMetadata(final byte[] urlHash) { public URIMetadataNode getMetadata(final byte[] urlHash) {
if (urlHash == null) return null; if (urlHash == null) return null;
return getMetadata(urlHash, null, 0.0f); return getMetadata(urlHash, null, 0L);
} }
private URIMetadataNode getMetadata(final byte[] urlHash, final WordReferenceVars wre, final float score) { private URIMetadataNode getMetadata(final byte[] urlHash, final WordReferenceVars wre, final long score) {
String u = ASCII.String(urlHash); String u = ASCII.String(urlHash);
// get the metadata from Solr // get the metadata from Solr

Loading…
Cancel
Save