[
https://issues.apache.org/jira/browse/SOLR-4591?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13605365#comment-13605365
]
Andrew Lundgren edited comment on SOLR-4591 at 3/18/13 5:13 PM:
----------------------------------------------------------------
I might be mistaken here, but the usage seems like it would be more difficult
to use this, then just the method to the NamedList.
The specific use case I am targeting is the init call in a component derived
from a SearchComponent. It passes in a NamedList. The component code I have
seen, (as well as mine) extracts the configuration parameters directly from the
NamedList.
One way I have seen this handled is some code like this for each value:
// Default initialized as member
String neededConfig=defaultStringValue;
Object obj= args.get("key");
if(obj!=null) {
try{
String value=(String)obj;
if(value.empty()) {
neededConfig=value;
}
} catch (ClassCastException) {
// deal with it as appropriate
}
}
The update I added allows you to do it like this:
Sting neededConfig;
try{
neededConfig=args.getDefault("key",defaultStringValue);
} catch (ClassCastException) {
// deal with it as appropriate
}
As I said, I might be mistaken but I think that using the DefaultSolrParams
here would not save you much, if any code. (Though I admit, I haven't seen
this used any other Component's init methods, and doing a grep across the solr
code didn't show many any.)
was (Author: lundgren):
I might be mistaken here, but the usage seems like it would be more
difficult to use this, then just the method to the NamedList.
The specific use case I am targeting is the init call in a component derived
from a SearchComponent. It passes in a NamedList. The other code, (as well as
mine) extracts the configuration parameters directly from the NamedList.
One way I have seen this handled is some code like this for each value:
// Default initialized as member
String neededConfig=defaultStringValue;
Object obj= args.get("key");
if(obj!=null) {
try{
String value=(String)obj;
if(value.empty()) {
neededConfig=value;
}
} catch (ClassCastException) {
// deal with it as appropriate
}
}
The update I added allows you to do it like this:
Sting neededConfig;
try{
neededConfig=args.getDefault("key",defaultStringValue);
} catch (ClassCastException) {
// deal with it as appropriate
}
As I said, I might be mistaken but I think that using the DefaultSolrParams
here would not save you much, if any code. (Though I admit, I haven't seen
this used any other Component's init methods, and doing a grep across the solr
code didn't show many any.)
> Add NamedList.getDefault to get values or use a defaulted value
> ---------------------------------------------------------------
>
> Key: SOLR-4591
> URL: https://issues.apache.org/jira/browse/SOLR-4591
> Project: Solr
> Issue Type: Improvement
> Components: search
> Reporter: Andrew Lundgren
> Priority: Trivial
> Attachments: SOLR-4591.patch, SOLR-4591.patch
>
>
> I seem to be putting a fair amount of code in my components to support having
> default values for keys that may not be specified in the solrconfig.xml
> Add a function to NamedList that supports getting a value with the option of
> using a default.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]