I could have resolved for discrete faceting adding fields to the current document. Now I reindex my small dataset (1.5M docs) to check the performance. In the second step I'll must manage dynamic range faceting.
For the first step I resolved using a custom FacetsConfig in order to change the signature for the method "Build". I have create a method "CustomBuild", <code> class CustomFacetsConfig extends FacetsConfig { private void checkSeen(Set<String> seenDims, String dim) { if (seenDims.contains(dim)) { throw new IllegalArgumentException("dimension \"" + dim + "\" is not multiValued, but it appears more than once in this document"); }
seenDims.add(dim); }
private void processSSDVFacetFields(Map<String, List<SortedSetDocValuesFacetField>> byField, Document doc) throws IOException { //System.out.println("process SSDV: " + byField); for (Map.Entry<String, List<SortedSetDocValuesFacetField>> ent : byField.entrySet()) {
String indexFieldName = ent.getKey(); //System.out.println(" field=" + indexFieldName);
for (SortedSetDocValuesFacetField facetField : ent.getValue()) { FacetLabel cp = new FacetLabel(facetField.dim, facetField.label); String fullPath = pathToString(cp.components, cp.length); //System.out.println("add " + fullPath); // For facet counts: doc.add(new SortedSetDocValuesField(indexFieldName, new BytesRef(fullPath))); // For drill-down: doc.add(new StringField(indexFieldName, fullPath, Store.NO)); doc.add(new StringField(indexFieldName, facetField.dim, Store.NO)); }
} }
public Document CustomBuild(Document doc, Document destDocument) throws IOException { // Find all FacetFields, collated by the actual field: //Map<String, List<FacetField>> byField = new HashMap<>();
// ... and also all SortedSetDocValuesFacetFields: Map<String, List<SortedSetDocValuesFacetField>> dvByField = new HashMap<>();
// ... and also all AssociationFacetFields //Map<String, List<AssociationFacetField>> assocByField = new HashMap<>();
Set<String> seenDims = new HashSet<>();
for (IndexableField field : doc.getFields()) { if (field.fieldType() == SortedSetDocValuesFacetField.TYPE) { SortedSetDocValuesFacetField facetField = (SortedSetDocValuesFacetField) field; FacetsConfig.DimConfig dimConfig = getDimConfig(facetField.dim); if (dimConfig.multiValued == false) { checkSeen(seenDims, facetField.dim); }
String indexFieldName = dimConfig.indexFieldName; List<SortedSetDocValuesFacetField> fields = dvByField.get(indexFieldName); if (fields == null) { fields = new ArrayList<>(); dvByField.put(indexFieldName, fields); }
fields.add(facetField); }
}
//Document result = new Document(); processSSDVFacetFields(dvByField, destDocument); //return result; return destDocument;
} } </code>
I use this class on my FieldBridge inside the method "set" : <code> @Override public void set(String name, Object value, Document document, LuceneOptions luceneOptions) { .... CustomFacetsConfig config = new CustomFacetsConfig(); config.setIndexFieldName(indexField, indexField + "_facet"); Document doc = new Document(); doc.add(new SortedSetDocValuesFacetField(indexField, fieldValueStr)); config.CustomBuild(doc, document); .... }
</code>
|