You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by "Avlesh Singh (JIRA)" <ji...@apache.org> on 2009/08/11 13:30:15 UTC

[jira] Created: (SOLR-1357) SolrInputDocument cannot process dynamic fields

SolrInputDocument cannot process dynamic fields
-----------------------------------------------

                 Key: SOLR-1357
                 URL: https://issues.apache.org/jira/browse/SOLR-1357
             Project: Solr
          Issue Type: Improvement
          Components: clients - java
            Reporter: Avlesh Singh


Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.

This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.

This should be supported
{code:java}
//This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}
Map<String, String> brands= new HashMap<String, String>();
brands.put("Nokia", 1000);
brands.put("Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

We can think of supporting this too ...
{code:java}
//This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
Map<String, String> brands= new HashMap<String, String>();
brands.put("Nokia", 1000);
brands.put("Samsung", 100);

SolrInputDocument doc = new SolrInputDocument();
doc.addField("brands_*", brands);
{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784129#action_12784129 ] 

Lars Grote commented on SOLR-1357:
----------------------------------

Hello Noble,
I'm sorry to bother you, but I don't understand the problem.

Can you please explain what you mean by the following:
{quote}
The problem is that the same bean canot be added to Solr w/ the same annotation. 
{quote}

Maybe I'm missing something, but at the moment I don't know what. Is it possible that you give a code example of the 'bad' design? So that I can fix the patch.

Regards, Lars

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jean Baptiste Pionnier updated SOLR-1357:
-----------------------------------------

    Comment: was deleted

(was: Thank you very much Noble.
My name is missing in changes.txt :-))

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch, SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784449#action_12784449 ] 

Lars Grote commented on SOLR-1357:
----------------------------------

Hey Noble,
I have a question ... again.

The question is somehow related to the the issue [SOLR-1129|https://issues.apache.org/jira/browse/SOLR-1129]. 

I copied the loop of Jean, and started implementing the unit test and came across a problem.
The code below is copied from the existing unittest.

Assume you have two fields annotated like this:
{code:title=TestDocumentObjectBinder .java}
@Field("supplier_*")
Map<String, List<String>> supplier;

@Field("supplier_*")
public void setAllSuppliers(String[] allSuppliers){
     this.allSuppliers = allSuppliers;
}
{code}

In my opinion the second field should be ignored when the bean is converted to the SolrImportDocument (it is not ignored in the current implementation). Otherwise you get in trouble when you try to get the bean out and try to put it back in.
So I would ignore all fields that are annotated as a dynamic field, an are not of the type Map when converting a Bean to a SolrInputDocument. 
When converting a SolrDocument to a Bean, it should be like it is now (not ignored, the field "allSuppliers" is injected with all Suppliers).

What do you think?

Regards, Lars


> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784608#action_12784608 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

The second one is not ignored. In fact this is not a robust OR mapping tool. if the user makes mistakes he is likely to get wrong data. This is intended to be a simple helper utility for users of POJOs. 

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12788664#action_12788664 ] 

Jean Baptiste Pionnier commented on SOLR-1357:
----------------------------------------------

Thank you very much Noble.
My name is missing in changes.txt :-)
Thanks Noble.

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch, SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784150#action_12784150 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

assume that the data that is fetched works as follows

{code:java}
bean.getBrands().get("Nokia");
bean.getBrands().get("Samsung");
{code}

So if I do a an add w/ the same bean as follows
{code:java}
solrServer.add(bean);
{code}
it adds the document with names as "Nokia" and "Samsung" instead of "Nokia_Brands" and "Samsung_Brands" . Atleast that is the implementation now.


> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 11:12 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  {{org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()}}
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12741854#action_12741854 ] 

Noble Paul edited comment on SOLR-1357 at 8/11/09 6:27 AM:
-----------------------------------------------------------

for the bean
{code:java}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}
{code}


the following should not work
{code:java}
brands.put("Nokia", 1000);
brands.put("Samsung", 100);
{code}

but this should work
{code:java}
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);
{code}

we may not need to support it is SolrInputDocument


      was (Author: noble.paul):
    for the bean
{code:java}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}
{code}


the following should not work
{code:java}
brands.put("Nokia", 1000);
brands.put("brands_Samsung", 100);
{code}

but this should work
{code:java}
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);
{code}

we may not need to support it is SolrInputDocument

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784192#action_12784192 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

bq.put the correct field name and get the correct field name
+1

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 11:01 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()
{code}
 for (DocField field : fields) {
     doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
 for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
             Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
 }
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()
{code}
                               for (DocField field : fields) {
                                               doc.setField( field.name, field.get( obj ), 1.0f );
                               }
{code}

Becomes

{code}
                               for (DocField field : fields) {

                                               if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
                                                               Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);
                                                               for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                                                                              doc.setField(e.getKey(), e.getValue(), 1.0f);
                                                               }
                                               } else {
                                                               doc.setField(field.name, field.get(obj), 1.0f);
                                               }

                               }
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Grote updated SOLR-1357:
-----------------------------

    Attachment: SOLR-1357.patch

So here is the patch. Maybe you can have a look at the testcase and the comment there, line 140. Just to make sure that this is the desired behavior.
Regards, Lars

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch, SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 11:07 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()

{code}
 for (DocField field : fields) {
     doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
 for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
             Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
 }
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12741854#action_12741854 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

for the bean
{code:java}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}
{code}


the following should not work
{code:java}
brands.put("Nokia", 1000);
brands.put("brands_Samsung", 100);
{code}

but this should work
{code:java}
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);
{code}

we may not need to support it is SolrInputDocument


> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784188#action_12784188 ] 

Lars Grote edited comment on SOLR-1357 at 12/1/09 12:03 PM:
------------------------------------------------------------

First of all, you are right there is someting wrong with the implementation.

The behavior should be the following

The Bean should act like schon above. Add Brands, get Brands ... The SolrInputDocument should store the values with the full name i.e. "nokia_brands", that's why I'm replacing the "*" with the key. The idear was that you can access the value like this:
{code}
bean.getBrands('Nokia')
{code}
or like this:
{code}
solrDocument.getFieldValue("brands_Nokia")
{code}

Anyway, I just started writting a unittest: Create Item -> SolrInputDocument -> SolrDocument -> retriev with getBean ->  SolrInputDocument -> SolrDocument -> retriev with getBean 

And if I have a Field like this:
{code}
@Field("supplier_simple_*")
Map<String, String> supplier_simple;
{code}
everything is fine and green. But if I try the same with a Filed like this:
{code}
@Field("supplier_*")
Map<String, List<String>> supplier;
{code}
I does not work, and at the moment I don't know why. So you are right, I'm having a closer look at this in the next few days, and hopefully I'll come back with a patch ;)
Regards Lars





      was (Author: lgrote):
    First of all, you are right there is someting wrong with the implementation.

The behavior should be the following

The Bean should act like schon above. Add Brands, get Brands ... The SolrInputDocument should store the values with the full name i.e. "nokia_brands", that's why I'm replacing the "*" with the key. The idear was that you can access the value like this:
{code}

bean.getBrands('Nokia')


  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784163#action_12784163 ] 

Lars Grote commented on SOLR-1357:
----------------------------------

Thanks for the claification!
Indeed that would be VERY bad design. But it is not what I intended to do. This would be the behavior if I had copied the loop of Jean. In the Patch the loop has a modification.

Have look at the inner loop. I think this should solve the problem.
{code:title=DocumentObjectBinder.java Line 91 to 102}
    for (DocField field : fields) {
		if (field.dynamicFieldNamePatternMatcher != null
				&& field.get(obj) != null && field.isContainedInMap) {
			Map<String, Object> mapValue = (HashMap<String, Object>) field
					.get(obj);

			for (Map.Entry<String, Object> e : mapValue.entrySet()) {
				doc.setField(field.name.replaceFirst("\\*", e.getKey()), e.getValue(), 1.0f);
			}
		} else {
			doc.setField(field.name, field.get(obj), 1.0f);
		}
	}
{code}

I think I'll create a patch for the testcase too, then we can see the behavior more clearly. 

What do you think about the snippet above? Do I miss something?
Regards ,Lars


> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784196#action_12784196 ] 

Lars Grote commented on SOLR-1357:
----------------------------------

2 to 1 you win!

I'll implement that and update the unittest in the next few days.
Regards, Lars

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784222#action_12784222 ] 

Jean Baptiste Pionnier commented on SOLR-1357:
----------------------------------------------

ok, Thank you very much.

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Grote updated SOLR-1357:
-----------------------------

    Comment: was deleted

(was: provides the behavior like shown in my post on November the 26.  2009)

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12782925#action_12782925 ] 

Lars Grote commented on SOLR-1357:
----------------------------------

Hello,
I think the way Avlesh suggested is more intuitive. At least I tried exactly that and wondered why it did not work.

This is what I think would be the best:

{code:java}
// a Field like this:
@Field("*_brands")
Map<String,Integer> brands;
{code}

you should add data like this:
{code:java}
brands.put("Nokia", 1000);
brands.put("Samsung", 100);
{code}

and get the data out like this:
{code:java}
bean.getBrands().get("Nokia");
bean.getBrands().get("Samsung");
{code}

I used the idear of Jean and enhanced it to work like shown above.
I attached a patch for this, maybe someone can have a look. It is not well tested.

I have never upload a Patch or something before. so if i'm doing something wrong, or do not follow the rules or anything.
Please tell me.

Regards, Lars


> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Shalin Shekhar Mangar (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784191#action_12784191 ] 

Shalin Shekhar Mangar commented on SOLR-1357:
---------------------------------------------

Solr does not need to add any intelligence here. Lets keep it a dumb and simple system, put the correct field name and get the correct field name. The behavior should be to put brands_Nokia and get back brands_Nokia for a dynamic field brands_*. The same thing is done for non-solrj clients and the solr responses.

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 11:02 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()

{code}
 for (DocField field : fields) {
     doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
 for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
             Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
 }
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()
{code}
 for (DocField field : fields) {
     doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
 for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
             Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
 }
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 11:12 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  {{org.apache.solr.client.solrj.beans.DocumentObjectBinder.toSolrInputDocument()}}
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  {{org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()}}
\\
\\
{code:title=DocumentObjectBinder.java}
for (DocField field : fields) {
      doc.setField( field.name, field.get( obj ), 1.0f );
}
{code}

Becomes

{code}
for (DocField field : fields) {
      if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
            Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);

            for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                  doc.setField(e.getKey(), e.getValue(), 1.0f);
            }
      } else {
            doc.setField(field.name, field.get(obj), 1.0f);
      }
}
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Avlesh Singh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12741915#action_12741915 ] 

Avlesh Singh commented on SOLR-1357:
------------------------------------

My point is that when a user has already annotated the field as "brand_*", appending them to keys of the Map is counter intuitive. This also goes against the behavior in SOLR-1129.
As far as supporting the behavior in {{SolrInputDocument}} goes, unless there is some low level API restriction, I would say we should support it.

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Avlesh Singh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12741910#action_12741910 ] 

Avlesh Singh commented on SOLR-1357:
------------------------------------

Well, I don't see a reason behind the proposed behavior (brand_nokia versus nokia), Noble. And why do you think {{SolrInputDocument}} should not facilitate this?

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Noble Paul resolved SOLR-1357.
------------------------------

    Resolution: Fixed

committed r886127
Thanks Lars

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch, SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784121#action_12784121 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

bq.I think the way Avlesh suggested is more intuitive. At least I tried exactly that and wondered why it did not work.

What i feel is that it is not consistent. The problem is that the same bean canot be added to Solr w/ the same annotation. That is not a very good design

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12742220#action_12742220 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

bq.My point is that when a user has already annotated the field as "brand_*", appending them to keys of the Map is counter intuitive.

IMHO It would be more clear if the fields are created in the same name as the user input. appending it to the wild card part is not so obvious. 

This is how serialization/deserialization works.

When I fetch an instance of MyBean ,it  contains the keys as "brands_Nokia" and brands_Samsung" . When I store it back why should I chop off the "brands_" part. I should be able to put back in the same Object into Solr w/o modifying it

bq.And why do you think SolrInputDocument should not facilitate this?

I'm not against the idea itself. I just meant that it is beyond the scope of this issue. Moreover, SolrInputDocument does not have a problem in achieving this requirement .

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12788664#action_12788664 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 12/10/09 11:02 AM:
-------------------------------------------------------------------------

Thank you very much Noble.
My name is missing in changes.txt :-)

      was (Author: gibbus):
    Thank you very much Noble.
My name is missing in changes.txt :-)
Thanks Noble.
  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch, SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784183#action_12784183 ] 

Noble Paul commented on SOLR-1357:
----------------------------------

Please clarify what the behavior is  going to be? 

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Noble Paul (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Noble Paul reassigned SOLR-1357:
--------------------------------

    Assignee: Noble Paul

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier commented on SOLR-1357:
----------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()

                               for (DocField field : fields) {
                                               doc.setField( field.name, field.get( obj ), 1.0f );
                               }

Becomes
                               for (DocField field : fields) {

                                               if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
                                                               Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);
                                                               for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                                                                              doc.setField(e.getKey(), e.getValue(), 1.0f);
                                                               }
                                               } else {
                                                               doc.setField(field.name, field.get(obj), 1.0f);
                                               }

                               }

This modification allows the following :

public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);


Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12784188#action_12784188 ] 

Lars Grote commented on SOLR-1357:
----------------------------------

First of all, you are right there is someting wrong with the implementation.

The behavior should be the following

The Bean should act like schon above. Add Brands, get Brands ... The SolrInputDocument should store the values with the full name i.e. "nokia_brands", that's why I'm replacing the "*" with the key. The idear was that you can access the value like this:
{code}

bean.getBrands('Nokia')



> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>            Assignee: Noble Paul
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Lars Grote (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lars Grote updated SOLR-1357:
-----------------------------

    Attachment: SOLR-1357.patch

provides the behavior like shown in my post on November the 26.  2009

> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>         Attachments: SOLR-1357.patch
>
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (SOLR-1357) SolrInputDocument cannot process dynamic fields

Posted by "Jean Baptiste Pionnier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SOLR-1357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780512#action_12780512 ] 

Jean Baptiste Pionnier edited comment on SOLR-1357 at 11/20/09 10:58 AM:
-------------------------------------------------------------------------

I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()
{code}
                               for (DocField field : fields) {
                                               doc.setField( field.name, field.get( obj ), 1.0f );
                               }
{code}

Becomes

{code}
                               for (DocField field : fields) {

                                               if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
                                                               Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);
                                                               for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                                                                              doc.setField(e.getKey(), e.getValue(), 1.0f);
                                                               }
                                               } else {
                                                               doc.setField(field.name, field.get(obj), 1.0f);
                                               }

                               }
{code}

This modification allows the following :
{code}
public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);
{code}

Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?


      was (Author: gibbus):
    I have not been able to set dynamic fields via annotations in SolrJ 1.4.
I have modified the following loop in  org.apache.solr.client.solrj.beans.DocumentObjectBinder.  toSolrInputDocument()

                               for (DocField field : fields) {
                                               doc.setField( field.name, field.get( obj ), 1.0f );
                               }

Becomes
                               for (DocField field : fields) {

                                               if (field.dynamicFieldNamePatternMatcher != null && field.get(obj) != null && field.isContainedInMap) {
                                                               Map<String, Object> mapValue = (HashMap<String, Object>) field.get(obj);
                                                               for (Map.Entry<String, Object> e : mapValue.entrySet()) {
                                                                              doc.setField(e.getKey(), e.getValue(), 1.0f);
                                                               }
                                               } else {
                                                               doc.setField(field.name, field.get(obj), 1.0f);
                                               }

                               }

This modification allows the following :

public class MyBean{
  @Field("brands_*)
  Map<String, Integer> brands;
  
  ...
}


Map<String, String> brands= new HashMap<String, String>();
brands.put("brands_Nokia", 1000);
brands.put("brands_Samsung", 100);

MyBean myBean = new MyBean();
myBean.setBrands(brands);
solrServer.addBean(myBean);


Unfortunately, I have not been able to find the correct process to submit this patch to SolrJ repository for official review. 
Would you so kind as to inform me of the necessary steps to include this patch (or another to the same effect) in future revisions of SolrJ ?

  
> SolrInputDocument cannot process dynamic fields
> -----------------------------------------------
>
>                 Key: SOLR-1357
>                 URL: https://issues.apache.org/jira/browse/SOLR-1357
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>            Reporter: Avlesh Singh
>
> Adding data via {{SolrInputDocument}} is normally done by calling the {{addField}} method with a field name, field value and an optional boost.  In case of dynamic fields, if field names are known upfront, then caller of this method just passes in the right name and it automatically works.
> This does not go well with users who use {{@interface Field}} annotations for automatic binding. 
> As of SOLR-1129, users can annotate {{Map<String, String> propertyName}} with {{@Field ("field_*")}} kind of annotations to bind dynamic field data to. {{SolrInputDocument}} should exhibit the same behavior.  The field {{value}} currently supported are - primitive, array, collection or an instance of Iterable. It can also take {{Map}} as values. If the field, for which {{addField}} method is called, is of dynamicField type (which can be derived from the field name), then the keys of the {{Map}}, passed as value, should be used to "compose" the correct field name.
> This should be supported
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> public class MyBean{
>   @Field("brands_*)
>   Map<String, Integer> brands;
>   
>   ...
> }
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> MyBean myBean = new MyBean();
> myBean.setBrands(brands);
> solrServer.addBean(myBean);
> {code}
> We can think of supporting this too ...
> {code:java}
> //This code sample should populate the dynamic fields "brands_Nokia" and "brands_Samsung"
> Map<String, String> brands= new HashMap<String, String>();
> brands.put("Nokia", 1000);
> brands.put("Samsung", 100);
> SolrInputDocument doc = new SolrInputDocument();
> doc.addField("brands_*", brands);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.