on remote Solr search take only locally enabled schema fields from remote solrdocument for the inputdocument added to local index

pull/1/head
reger 12 years ago
parent d31a109efe
commit f291d60c5f

@ -24,6 +24,7 @@ import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.yacy.search.index.SolrConfiguration;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
@ -357,18 +358,31 @@ public enum YaCySchema implements Schema {
* This is useful if a document from the search index shall be modified and indexed again.
* This shall be used as replacement of ClientUtils.toSolrInputDocument because we remove some fields
* which are created automatically during the indexing process.
* Additionally, only locally enabled fields are included in the return SolrInputDocument.
* if SolrConfiguration is NULL no check of local enabled fields is performed
* @param doc the solr document
* @param cfg solr schema to check field names (null = no name check)
* @return a solr input document
*/
public static SolrInputDocument toSolrInputDocument(SolrDocument doc) {
public static SolrInputDocument toSolrInputDocument(SolrDocument doc, SolrConfiguration cfg) {
//TODO: considere to move this procedure to a higher level class where SolrConfig is available
SolrInputDocument sid = new SolrInputDocument();
Set<String> omitFields = new HashSet<String>();
Set<String> omitFields = new HashSet<String>(3);
omitFields.add(YaCySchema.author_sxt.getSolrFieldName());
if (cfg == null) { // proceed without field name check
omitFields.add(YaCySchema.coordinate_p.getSolrFieldName() + "_0_coordinate");
omitFields.add(YaCySchema.coordinate_p.getSolrFieldName() + "_1_coordinate");
omitFields.add(YaCySchema.author_sxt.getSolrFieldName());
for (String name: doc.getFieldNames()) {
if (!omitFields.contains(name)) sid.addField(name, doc.getFieldValue(name), 1.0f);
}
} else {
// coordinage_p _0_coordinate not in YaCySchema
for (String name: doc.getFieldNames()) {
if (cfg.contains(name)) { // check each field if enabled in local Solr schema
if (!omitFields.contains(name)) sid.addField(name, doc.getFieldValue(name), 1.0f);
}
}
}
return sid;
}
}

@ -105,7 +105,6 @@ import net.yacy.search.EventTracker;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.search.index.Segment;
import net.yacy.search.query.QueryModifier;
import net.yacy.search.query.SearchEvent;
import net.yacy.search.query.SecondarySearchSuperviser;
import net.yacy.search.snippet.TextSnippet;
@ -1148,7 +1147,7 @@ public final class Protocol {
// passed all checks, store url
if (!localsearch) {
try {
event.query.getSegment().fulltext().putDocument(YaCySchema.toSolrInputDocument(doc));
event.query.getSegment().fulltext().putDocument(YaCySchema.toSolrInputDocument(doc,Switchboard.getSwitchboard().index.fulltext().getSolrScheme()));
ResultURLs.stack(
ASCII.String(urlEntry.url().hash()),
urlEntry.url().getHost(),

@ -2248,7 +2248,7 @@ public final class Switchboard extends serverSwitch {
url = new DigestURI((String) doc.getFieldValue(YaCySchema.sku.getSolrFieldName()), ASCII.getBytes((String) doc.getFieldValue(YaCySchema.id.getSolrFieldName())));
int clickdepth = SolrConfiguration.getClickDepth(index.urlCitation(), url);
if (oldclickdepth == null || oldclickdepth.intValue() != clickdepth) proccount_clickdepthchange++;
SolrInputDocument sid = YaCySchema.toSolrInputDocument(doc);
SolrInputDocument sid = YaCySchema.toSolrInputDocument(doc, null);
sid.setField(YaCySchema.clickdepth_i.getSolrFieldName(), clickdepth);
// refresh the link count; it's 'cheap' to do this here

@ -436,7 +436,7 @@ public class Segment {
// switch attribute also in all existing documents (which should be exactly only one!)
SolrDocumentList docs = this.fulltext.getSolr().query(checkfield.getSolrFieldName() + ":" + checkstring + " AND " + uniquefield.getSolrFieldName() + ":true", 0, 1000);
for (SolrDocument doc: docs) {
SolrInputDocument sid = YaCySchema.toSolrInputDocument(doc);
SolrInputDocument sid = YaCySchema.toSolrInputDocument(doc, null);
sid.setField(uniquefield.getSolrFieldName(), false);
this.fulltext.getSolr().add(sid);
}

Loading…
Cancel
Save