- setting the same default ranking in the solr interface as for YaCy

search interfaces if no other ranking attributes are given
- using the YaCy ranking in the GSA interface only if there was not
given a GSA-style sort attribute
- to avoid confusion about correct ranking attributes, only the default
'0'-ranking profile is used and not scenario-adopted (site, date)
because that should be configurable in the web interface before it is
used actually for ranking.
pull/1/head
Michael Peter Christen 12 years ago
parent a20941c067
commit 082e3274d6

@ -23,7 +23,6 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
import net.yacy.cora.document.UTF8; import net.yacy.cora.document.UTF8;
import net.yacy.cora.federate.solr.Ranking; import net.yacy.cora.federate.solr.Ranking;
@ -116,11 +115,24 @@ public class searchresult {
post.put(CommonParams.ROWS, post.remove("num")); post.put(CommonParams.ROWS, post.remove("num"));
post.put(CommonParams.ROWS, Math.min(post.getInt(CommonParams.ROWS, 10), (authenticated) ? 5000 : 100)); post.put(CommonParams.ROWS, Math.min(post.getInt(CommonParams.ROWS, 10), (authenticated) ? 5000 : 100));
Ranking ranking = sb.index.fulltext().getDefaultConfiguration().getRanking(0); // set ranking
String bq = ranking.getBoostQuery(); if (post.containsKey("sort")) {
String bf = ranking.getBoostFunction(); // if a gsa-style sort attribute is given, use this to set the solr sort attribute
if (bq.length() > 0) post.put("bq", bq); // a boost query that moves double content to the back GSAResponseWriter.Sort sort = new GSAResponseWriter.Sort(post.get(CommonParams.SORT, ""));
if (bf.length() > 0) post.put(ranking.getMethod() == Ranking.BoostFunctionMode.add ? "bf" : "boost", bf); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29 String sorts = sort.toSolr();
if (sorts == null) {
post.remove(CommonParams.SORT);
} else {
post.put(CommonParams.SORT, sorts);
}
} else {
// if no such sort attribute is given, use the ranking as configured for YaCy
Ranking ranking = sb.index.fulltext().getDefaultConfiguration().getRanking(0);
String bq = ranking.getBoostQuery();
String bf = ranking.getBoostFunction();
if (bq.length() > 0) post.put("bq", bq); // a boost query that moves double content to the back
if (bf.length() > 0) post.put(ranking.getMethod() == Ranking.BoostFunctionMode.add ? "bf" : "boost", bf); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29
}
post.put(CommonParams.FL, post.put(CommonParams.FL,
CollectionSchema.content_type.getSolrFieldName() + ',' + CollectionSchema.content_type.getSolrFieldName() + ',' +
CollectionSchema.id.getSolrFieldName() + ',' + CollectionSchema.id.getSolrFieldName() + ',' +
@ -137,16 +149,10 @@ public class searchresult {
post.put("hl.simple.pre", "<b>"); post.put("hl.simple.pre", "<b>");
post.put("hl.simple.post", "</b>"); post.put("hl.simple.post", "</b>");
post.put("hl.fragsize", Integer.toString(SearchEvent.SNIPPET_MAX_LENGTH)); post.put("hl.fragsize", Integer.toString(SearchEvent.SNIPPET_MAX_LENGTH));
GSAResponseWriter.Sort sort = new GSAResponseWriter.Sort(post.get(CommonParams.SORT, ""));
String sorts = sort.toSolr();
if (sorts == null) {
post.remove(CommonParams.SORT);
} else {
post.put(CommonParams.SORT, sorts);
}
String[] site = post.remove("site"); // example: col1|col2 String[] site = post.remove("site"); // example: col1|col2
String[] access = post.remove("access"); //String[] access = post.remove("access");
String[] entqr = post.remove("entqr"); //String[] entqr = post.remove("entqr");
// add sites operator // add sites operator
if (site != null && site[0].length() > 0) { if (site != null && site[0].length() > 0) {
@ -184,6 +190,7 @@ public class searchresult {
} }
// set some context for the writer // set some context for the writer
/*
Map<Object,Object> context = req.getContext(); Map<Object,Object> context = req.getContext();
context.put("ip", header.get("CLIENTIP", "")); context.put("ip", header.get("CLIENTIP", ""));
context.put("client", "vsm_frontent"); context.put("client", "vsm_frontent");
@ -191,6 +198,7 @@ public class searchresult {
context.put("site", site == null ? "" : site); context.put("site", site == null ? "" : site);
context.put("access", access == null ? "p" : access[0]); context.put("access", access == null ? "p" : access[0]);
context.put("entqr", entqr == null ? "3" : entqr[0]); context.put("entqr", entqr == null ? "3" : entqr[0]);
*/
// write the result directly to the output stream // write the result directly to the output stream
Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset));

@ -28,6 +28,7 @@ import java.util.Map;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import net.yacy.cora.document.UTF8; import net.yacy.cora.document.UTF8;
import net.yacy.cora.federate.solr.Ranking;
import net.yacy.cora.federate.solr.SolrServlet; import net.yacy.cora.federate.solr.SolrServlet;
import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector; import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector;
import net.yacy.cora.federate.solr.responsewriter.EnhancedXMLResponseWriter; import net.yacy.cora.federate.solr.responsewriter.EnhancedXMLResponseWriter;
@ -161,6 +162,16 @@ public class select {
if (!post.containsKey(CommonParams.ROWS)) post.put(CommonParams.ROWS, post.remove("maximumRecords", 10)); // sru patch if (!post.containsKey(CommonParams.ROWS)) post.put(CommonParams.ROWS, post.remove("maximumRecords", 10)); // sru patch
post.put(CommonParams.ROWS, Math.min(post.getInt(CommonParams.ROWS, 10), (authenticated) ? 10000 : 100)); post.put(CommonParams.ROWS, Math.min(post.getInt(CommonParams.ROWS, 10), (authenticated) ? 10000 : 100));
// set default ranking if this is not given in the request
if (!post.containsKey("sort")) {
if (!post.containsKey("defType")) post.put("defType", "edismax");
Ranking ranking = sb.index.fulltext().getDefaultConfiguration().getRanking(0);
String bq = ranking.getBoostQuery();
String bf = ranking.getBoostFunction();
if (!post.containsKey("bq") && bq.length() > 0) post.put("bq", bq); // a boost query that moves double content to the back
if (!(post.containsKey("bf") || post.containsKey("boost")) && bf.length() > 0) post.put(ranking.getMethod() == Ranking.BoostFunctionMode.add ? "bf" : "boost", bf); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29
}
// get a response writer for the result // get a response writer for the result
String wt = post.get(CommonParams.WT, "xml"); // maybe use /solr/select?q=*:*&start=0&rows=10&wt=exml String wt = post.get(CommonParams.WT, "xml"); // maybe use /solr/select?q=*:*&start=0&rows=10&wt=exml
QueryResponseWriter responseWriter = RESPONSE_WRITER.get(wt); QueryResponseWriter responseWriter = RESPONSE_WRITER.get(wt);

@ -386,7 +386,8 @@ public final class QueryParams {
final SolrQuery params = new SolrQuery(); final SolrQuery params = new SolrQuery();
params.setQuery(this.queryGoal.collectionQueryString(this.indexSegment.fulltext().getDefaultConfiguration()).toString()); params.setQuery(this.queryGoal.collectionQueryString(this.indexSegment.fulltext().getDefaultConfiguration()).toString());
params.setParam("defType", "edismax"); params.setParam("defType", "edismax");
Ranking ranking = indexSegment.fulltext().getDefaultConfiguration().getRanking(this.ranking.coeff_date == RankingProfile.COEFF_MAX ? 1 : (this.modifier.sitehash != null || this.modifier.sitehost != null) ? 2 : 0); // for a by-date ranking select different ranking profile Ranking ranking = indexSegment.fulltext().getDefaultConfiguration().getRanking(0);
//Ranking ranking = indexSegment.fulltext().getDefaultConfiguration().getRanking(this.ranking.coeff_date == RankingProfile.COEFF_MAX ? 1 : (this.modifier.sitehash != null || this.modifier.sitehost != null) ? 2 : 0); // for a by-date ranking select different ranking profile
String bq = ranking.getBoostQuery(); String bq = ranking.getBoostQuery();
String bf = ranking.getBoostFunction(); String bf = ranking.getBoostFunction();
if (bq.length() > 0) params.setParam("bq", bq); // a boost query that moves double content to the back if (bq.length() > 0) params.setParam("bq", bq); // a boost query that moves double content to the back

@ -1104,7 +1104,7 @@ public final class SearchEvent {
Element<URIMetadataNode> localEntryElement = this.nodeStack.sizeQueue() > 0 ? this.nodeStack.poll() : null; Element<URIMetadataNode> localEntryElement = this.nodeStack.sizeQueue() > 0 ? this.nodeStack.poll() : null;
URIMetadataNode node = localEntryElement == null ? null : localEntryElement.getElement(); URIMetadataNode node = localEntryElement == null ? null : localEntryElement.getElement();
if (node != null) { if (node != null) {
String solrsnippet = this.snippets.remove(ASCII.String(node.hash())); // we ca remove this because it's used only once String solrsnippet = this.snippets.remove(ASCII.String(node.hash())); // we can remove this because it's used only once
if (solrsnippet != null && solrsnippet.length() > 0) { if (solrsnippet != null && solrsnippet.length() > 0) {
final TextSnippet snippet = new TextSnippet(node.hash(), solrsnippet, true, ResultClass.SOURCE_CACHE, ""); final TextSnippet snippet = new TextSnippet(node.hash(), solrsnippet, true, ResultClass.SOURCE_CACHE, "");
ResultEntry re = new ResultEntry(node, this.query.getSegment(), this.peers, snippet, null, 0); ResultEntry re = new ResultEntry(node, this.query.getSegment(), this.peers, snippet, null, 0);

Loading…
Cancel
Save