I'm new to Apache Lucene. I'm using the latest version: 6.3.0 in combination with facet library. Based on the examples I found on github: https://github.com/apache/lucene-solr/tree/master/lucene/demo/src/java/org/apache/lucene/demo/facet
I have the following Document
Document doc = new Document();
doc.add(new FacetField("Author", "Bob"));
doc.add(new FacetField("Publish Date", "2010", "10", "15"));
doc.add(new FacetField("Tags", "A"));
doc.add(new FacetField("Tags", "B"));
//[FacetField(dim=Author path=[Bob]), FacetField(dim=Publish Date path=[2010, 10, 15]), FacetField(dim=Tags path=[A]), FacetField(dim=Tags path=[B])]
System.out.println(doc.getFields());
//null
System.out.println(doc.getField("Author"));
doc.getFields()
returns all the fields, but doc.getField("Author")
returns null.
Am I doing something wrong?
Digging further if I do something like this:
for(IndexableField myField:doc.getFields()){
System.out.println(myField.name());
}
The following is printed:
dummy
dummy
dummy
dummy
And if I do something like this doc.getField("dummy")
it will indeed return the first field(Author).
Looking at FacetField source code: https://github.com/apache/lucene-solr/blob/branch_6_3/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java It seems that all facet fields are created with "dummy": https://github.com/apache/lucene-solr/blob/branch_6_3/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java
public FacetField(String dim, String... path) {
super("dummy", TYPE);
Is this a bug?
As per my understanding, you are trying to retrieve the value of Author, which it should be returned as "Bob".
FacetField & Field are two different type of Fields in Lucene and they store the data in different manner. And FacetField is child class of Field class. To initialize the Field you needs the name of field, type & boolean value which denotes you want to retrieve the field or not.
And here is the example of Field initialization
Now, in order to store the documents, you should do it like this.
In order to undertand the solr Indeing & Searching using Solrj please rever this link.
I hope this helps.