title: Solr Hierarchy Numbering
body: <p>The example on <a href="https://cwiki.apache.org/confluence/display/solr/HierarchicalFaceting" rel="nofollow noreferrer">Solr's wiki page</a> shows a kind of indexed hierarchy nodes:</p>
  
  <pre><code>Doc#1: 0/NonFic, 1/NonFic/Law
  Doc#2: 0/NonFic, 1/NonFic/Sci
  Doc#3: 0/NonFic, 1/NonFic/Hist
  </code></pre>
  
  <p>How do I index my paths to achieve this? Do I manually split my paths, count the nodes, and generate these terms myself and store them as an array in Solr (multiValued field) or is it possible to configure <a href="https://lucene.apache.org/solr/guide/6_6/tokenizers.html#Tokenizers-PathHierarchyTokenizer" rel="nofollow noreferrer">Solr's path hierarchy tokenizer</a> to apply the indexes itself?</p>
  
  <p>For reference, I though about generating the paths like this:</p>
  
  <pre><code>public class DocumentPathBuilder {
  
      private List&lt;String&gt; nodes = new ArrayList&lt;&gt;();
  
      public static DocumentPathBuilder newInstance() {
          return new DocumentPathBuilder();
      }
  
      public static String escapeText(String input) {
          if (input == null)
              throw new NullPointerException("Cannot escape null input!");
          return input.replaceAll(ESearchDocumentPath.HIERARCHY_SEPERATOR, "").toUpperCase().trim();
      }
  
      public DocumentPathBuilder add(String node) {
          nodes.add(escapeText(node));
          return this;
      }
  
      public DocumentPathBuilder add(Collection&lt;String&gt; nodes) {
          this.nodes.addAll(nodes.stream()
                  .map(n-&gt;escapeText(n))
                  .collect(Collectors.toList())
          );
          return this;
      }
  
      public List&lt;String&gt; build() {
          List&lt;String&gt; result = new ArrayList&lt;&gt;();
          for (int i = 0; i &lt; nodes.size(); i++) {
              StringJoiner joiner = new StringJoiner(ESearchDocumentPath.HIERARCHY_SEPERATOR);
              joiner.add(""+i);
              for (int j = 0; j &lt;= i; j++) {
                  joiner.add(nodes.get(j));
              }
              result.add(joiner.toString()+ESearchDocumentPath.HIERARCHY_SEPERATOR);
          }
          return result;
      }
  }
  </code></pre>
  
  <p>Example input:  </p>
  
  <pre><code>  List&lt;String&gt; build = DocumentPathBuilder.newInstance()
                  .add("A")
                  .add("350")
                  .add(Arrays.asList("350-01", "FIGUTZRg"))
                  .build();
  </code></pre>
  
  <p>Output entries:</p>
  
  <pre><code>0 = "0&gt;A&gt;"
  1 = "1&gt;A&gt;350&gt;"
  2 = "2&gt;A&gt;350&gt;350-01&gt;"
  3 = "3&gt;A&gt;350&gt;350-01&gt;FIGUTZRG&gt;"
  </code></pre>
  
  <p>Also, what is the difference? If I store my generated values in a multiValued field, do I get the same result If Solr would have generated it with path tokenizer?</p>