0

I am trying to understand what is the best way to design my Solr Schema. and if there is a possibility to do it in a less complex way using solrJ.
I am currently working with solr's example server so i can understand how solr works. if i understood correctly so far, the way to define the following schema:

Book= { title: String,
        year: Int } 

Author = { name: String,
           books: [book] } <-- list/array of book objects 

is to use CopyFields:

<fields>
    <field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="books" type="string" indexed="true" stored="false" multiValued="false"/>
    <!-- books will contain: --> 
    <field name="title" type="string" indexed="true" stored="true" multiValued="true"/>
    <field name="year" type="int" indexed="true" stored="true"/>
</fields>
<copyField source="title" dest="books"/>
<copyField source="year" dest="books"/>

was i correct? if so, how do i upload a new author to my database? i tried to upload form my node.js server using solr-client:

function ADDONE(){
    var docs = [];
    //generate 4 docs.
    for(var i = 0; i <= 4 ; i++){
       var doc = {
            id : 20 + i , 
            name : "Author"+i ,
            books: [{title: "firstBook" , year: 1900+i} , 
                    {title: "SecondBook" , year: 1901+i} ]

       }
       docs.push(doc);
    }
    // Add documents to Solr
    client.add(docs,function(err,obj){
       if(err){
          console.log(err);
       }else{
          console.log(obj);
       }
    });

}
ADDONE();

But this won't work. what is the correct way to define each document? am i even close? the example i gave was written for node.js solr-client, but i prefer to use Java and it's solr Client (solrJ?).

I would also like to know how a contract a query for books form the years 1900 to 1910.

Thanks.

Roy
  • 221
  • 3
  • 8

2 Answers2

0

solr does not allow for structured objects. If you want to do this, you must define entities.

For example, passing with Data Import Request Handler

http://wiki.apache.org/solr/DataImportHandler#Full_Import_Example

So you can have one entity for book and one entity for author

Alexandre Ouicher
  • 856
  • 1
  • 9
  • 15
0

you can also use the dynamics fields

<fields>
    <field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="books" type="string" indexed="true" stored="false" multiValued="false"/>
    <dynamicField name="books_year_*"  type="string" indexed="true"  stored="true" multiValued="false"/>
    <dynamicField name="books_title_*"  type="string" indexed="true"  stored="true" multiValued="false"/>
    <field name="book_title" type="string" indexed="true" stored="true" multiValued="true"/>
    <copyField source="books_title_*" dest="book_title"/>
    <field name="book_year" type="string" indexed="true" stored="true" multiValued="true"/>
    <copyField source="books_year_*" dest="book_year"/>

</fields>

and with your method,

books: [{title: "firstBook" , year: 1900+i} => 
"books_title_"+i : firstBook
"books_year_"+i : 1900+i

Query:

select?q=book_year:"1970"
Alexandre Ouicher
  • 856
  • 1
  • 9
  • 15
  • Sounds good, can you give me an example of how would a query for all the authors that have books from some year range, so i will understand how to use it? (any general example would do it) – Roy Jul 30 '13 at 14:31
  • Added: ` ` and query: `select?q=book_year:"1910"` – Alexandre Ouicher Jul 30 '13 at 14:34