Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 308 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apache Lucene return facet fields from document

#1
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:

[To see links please register here]


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:

[To see links please register here]

It seems that all facet fields are created with "dummy":

[To see links please register here]


public FacetField(String dim, String... path) {
super("dummy", TYPE);

Is this a bug?
Reply

#2
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.

> public class FacetField extends Field

And here is the example of Field initialization

> Field pathField = new StringField("path", file.toString(),
> Field.Store.YES);<br/> doc.add(pathField);


Now, in order to store the documents, you should do it like this.

>SolrInputDocument doc = new SolrInputDocument();<br>
String id = "1";<br>
String author = "Erick";<br>
String text = "I love Solr book";<br>
doc.addField("id", id);<br>
doc.addField("author", title);<br>
> doc.addField("text", text);<br>

In order to undertand the solr Indeing & Searching using Solrj please rever this [link][1].

I hope this helps.


[1]:

[To see links please register here]

Reply

#3
I ran into the same issue myself. If you were to write said document and obtain it with a search, you'd see that FacetFields aren't actually stored as part of the document. Additionally, searching on a value in a FacetField doesn't work (returns 0 results). It'd be nice if there was a flag or something that would result in the field being written to both the taxonomy and to the index itself, but I think the issue is that the document index has several other attributes that don't apply to facet fields so they just keep them separate to avoid confusion.

The way I worked around it is by writing the field twice on the document: one as a FacetField and another field with the desired attributes.

Example:

Document doc = new Document();

// Add facet fields, not stored/searchable, but can be drilled down into
doc.add(new FacetField("Author", "Bob"));
...

// Add other fields
doc.add(new TextField("Author", "Bob", Store.YES));
...
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through