/** Build the example index. */
  private void index() throws IOException {
    IndexWriterConfig iwc =
        new IndexWriterConfig(new WhitespaceAnalyzer()).setOpenMode(OpenMode.CREATE);
    IndexWriter indexWriter = new IndexWriter(indexDir, iwc);

    // Writes facet ords to a separate directory from the main index
    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);

    Document doc = new Document();
    // 3 occurrences for tag 'lucene'
    doc.add(new IntAssociationFacetField(3, "tags", "lucene"));
    // 87% confidence level of genre 'computing'
    doc.add(new FloatAssociationFacetField(0.87f, "genre", "computing"));
    indexWriter.addDocument(config.build(taxoWriter, doc));

    doc = new Document();
    // 1 occurrence for tag 'lucene'
    doc.add(new IntAssociationFacetField(1, "tags", "lucene"));
    // 2 occurrence for tag 'solr'
    doc.add(new IntAssociationFacetField(2, "tags", "solr"));
    // 75% confidence level of genre 'computing'
    doc.add(new FloatAssociationFacetField(0.75f, "genre", "computing"));
    // 34% confidence level of genre 'software'
    doc.add(new FloatAssociationFacetField(0.34f, "genre", "software"));
    indexWriter.addDocument(config.build(taxoWriter, doc));

    indexWriter.close();
    taxoWriter.close();
  }
 /** Empty constructor */
 public AssociationsFacetsExample() {
   config = new FacetsConfig();
   config.setMultiValued("tags", true);
   config.setIndexFieldName("tags", "$tags");
   config.setMultiValued("genre", true);
   config.setIndexFieldName("genre", "$genre");
 }
 private static FacetsConfig getConfig() {
   FacetsConfig config = new FacetsConfig();
   config.setMultiValued("A", true);
   config.setMultiValued("B", true);
   config.setRequireDimCount("B", true);
   config.setHierarchical("D", true);
   return config;
 }
 private static void indexDocsWithFacetsNoTerms(
     IndexWriter indexWriter, TaxonomyWriter taxoWriter, Map<String, Integer> expectedCounts)
     throws IOException {
   Random random = random();
   int numDocs = atLeast(random, 2);
   FacetsConfig config = getConfig();
   for (int i = 0; i < numDocs; i++) {
     Document doc = new Document();
     addFacets(doc, config, false);
     indexWriter.addDocument(config.build(taxoWriter, doc));
   }
   indexWriter.commit(); // flush a segment
 }
 /**
  * Wraps an LeafReader, mapping ordinals according to the ordinalMap, using the provided {@link
  * FacetsConfig} which was used to build the wrapped reader.
  */
 public OrdinalMappingLeafReader(LeafReader in, int[] ordinalMap, FacetsConfig srcConfig) {
   super(in);
   this.ordinalMap = ordinalMap;
   facetsConfig = new InnerFacetsConfig();
   facetFields = new HashSet<>();
   for (DimConfig dc : srcConfig.getDimConfigs().values()) {
     facetFields.add(dc.indexFieldName);
   }
   // always add the default indexFieldName. This is because FacetsConfig does
   // not explicitly record dimensions that were indexed under the default
   // DimConfig, unless they have a custome DimConfig.
   facetFields.add(FacetsConfig.DEFAULT_DIM_CONFIG.indexFieldName);
 }