remove old vocabularies and synonyms before adding new

pull/10/head
Michael Peter Christen 10 years ago
parent 289018b559
commit 0aa6fcf259

@ -68,7 +68,7 @@
<classpathentry kind="lib" path="lib/httpmime-4.4.1.jar"/>
<classpathentry kind="lib" path="lib/noggit-0.6.jar"/>
<classpathentry kind="lib" path="lib/solr-core-5.2.0.jar" sourcepath="/Volumes/Uno/noBackup/Downloads/solr-5.2.0/solr/core/src/java"/>
<classpathentry kind="lib" path="lib/solr-solrj-5.2.0.jar" sourcepath="/Volumes/Uno/noBackup/Downloads/solr-5.2.0/solr/solrj/src/java"/>
<classpathentry kind="lib" path="lib/solr-solrj-5.2.0.jar" sourcepath="/Users/admin/Downloads/solr-5.2.1/solr/solrj/src/java"/>
<classpathentry kind="lib" path="lib/stax2-api-3.1.4.jar"/>
<classpathentry kind="lib" path="lib/woodstox-core-asl-4.4.1.jar"/>
<classpathentry kind="lib" path="lib/lucene-analyzers-common-5.2.0.jar"/>

@ -112,6 +112,14 @@ public class SchemaConfiguration extends Configuration implements Serializable {
return this.contains(field.getSolrFieldName());
}
public void remove(final SolrInputDocument doc, final SchemaDeclaration key) {
key.remove(doc);
}
public void remove(final SolrInputDocument doc, final String key) {
doc.removeField(key);
}
public void add(final SolrInputDocument doc, final SchemaDeclaration key, final String value) {
assert !key.isMultiValued() : "key = " + key.getSolrFieldName();
if ((isEmpty() || contains(key)) && (!this.lazy || (value != null && !value.isEmpty()))) key.add(doc, value);

@ -72,5 +72,7 @@ public interface SchemaDeclaration {
public void add(final SolrInputDocument doc, final double value);
public void add(final SolrInputDocument doc, final boolean value);
public void remove(final SolrInputDocument doc);
}

@ -101,6 +101,7 @@ import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
import org.eclipse.jetty.util.ConcurrentHashSet;
@ -1006,6 +1007,10 @@ public class CollectionConfiguration extends SchemaConfiguration implements Seri
}
public void enrich(SolrInputDocument doc, List<String> synonyms, Map<String, Set<String>> genericFacets) {
remove(doc, CollectionSchema.vocabularies_sxt); // delete old values
for (SolrInputField sif: doc) {
if (sif.getName().startsWith(CollectionSchema.VOCABULARY_PREFIX)) remove(doc, sif.getName());
}
if (this.isEmpty() || contains(CollectionSchema.vocabularies_sxt)) {
// write generic navigation
// there are no pre-defined solr fields for navigation because the vocabulary is generic
@ -1027,6 +1032,7 @@ public class CollectionConfiguration extends SchemaConfiguration implements Seri
}
if (vocabularies.size() > 0) add(doc, CollectionSchema.vocabularies_sxt, vocabularies);
}
remove(doc, CollectionSchema.synonyms_sxt); // delete old values
if (this.isEmpty() || contains(CollectionSchema.synonyms_sxt)) {
if (synonyms.size() > 0) add(doc, CollectionSchema.synonyms_sxt, synonyms);
}

@ -341,7 +341,7 @@ public enum CollectionSchema implements SchemaDeclaration {
public final String getComment() {
return this.comment;
}
@Override
public final void add(final SolrInputDocument doc, final String value) {
assert !this.isMultiValued();
@ -431,5 +431,9 @@ public enum CollectionSchema implements SchemaDeclaration {
doc.setField(this.getSolrFieldName(), value);
}
@Override
public final void remove(final SolrInputDocument doc) {
doc.removeField(this.getSolrFieldName());
}
}

@ -284,5 +284,9 @@ public enum WebgraphSchema implements SchemaDeclaration {
doc.setField(this.getSolrFieldName(), value);
}
@Override
public final void remove(final SolrInputDocument doc) {
doc.removeField(this.getSolrFieldName());
}
}

Loading…
Cancel
Save