You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by bhawna singh <si...@gmail.com> on 2011/08/18 22:15:29 UTC
Update field value in the document based on value of another field in
the document
Hi All,
I have a requirement to update a certain field value depending on the field
value of another field.
To elaborate-
I have a field called 'popularity' and a field called 'URL'. I need to
assign popularity value depending on the domain (URL) ( I have the
popularity and domain mapping in a text file).
I am using CSVRequestHandler to import the data.
What are the suggested ways to achieve this.
Your quick response is much appreciated.
Thanks,
Bhawna
Re: Update field value in the document based on value of another
field in the document
Posted by Chris Hostetter <ho...@fucit.org>.
: Now that I have set it up using UpdateProcessorChain, I am running into null
: exeception.
are you sure you pasted the correct stack trace? that's not a null
(pointer) exception it's an AbstractMethodError...
: Aug 20, 2011 10:48:43 AM org.apache.solr.common.SolrException log
: SEVERE: java.lang.AbstractMethodError at
: org.apache.solr.update.processor.UpdateRequestProcessorChain.createProcessor(UpdateRequestProcessorChain.java:74)
: at
: org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:53)
...that means that there is a missmatch between the classpath you used to
compile your code and the classpath used when running your code (otherwise
you would have gotten a compile error)
Check your versions I suspect you aren't compile against the version of
Solr thta you think you are.
-Hoss
Re: Update field value in the document based on value of another
field in the document
Posted by Erick Erickson <er...@gmail.com>.
Publishing stack traces does no good unless you also tell us what version
of Solr you are using. The source-file numbers do move around between
versions....
Also, what line in your code is at the root of this chain? The very first thing
I'd do is just comment out your custom code (i.e. just ahve the
super.processAdd)
in your code and build up from there. Some printlns might show the problem by
testing, for instance, that doc is not null (I can't imagine why it
would be, but it's been
said that "It's not the things you don't know that'll kill you, it's
the things you do
know that aren't true".....
Best
Erick
On Sat, Aug 20, 2011 at 2:39 PM, bhawna singh <si...@gmail.com> wrote:
> Now that I have set it up using UpdateProcessorChain, I am running into null
> exeception.
> Here is what I have-
> In SolrConfig.xml
> <updateRequestProcessorChain name="mychain" >
> <processor class="mysolr.AddConditionalFieldsFactory" >
> </processor>
> <processor class="solr.RunUpdateProcessorFactory" />
> <processor class="solr.LogUpdateProcessorFactory" />
> </updateRequestProcessorChain>
>
>
> <requestHandler name="/update/csv" class="solr.CSVRequestHandler"
> startup="lazy" >
> <lst name="defaults">
> <str name="update.chain">mychain</str>
> </lst>
> </requestHandler>
>
>
> Here is my java code-
> package mysolr;
>
>
> import java.io.IOException;
>
> import org.apache.solr.common.SolrInputDocument;
> import org.apache.solr.request.SolrQueryRequest;
> import org.apache.solr.request.SolrQueryResponse;
> import org.apache.solr.update.AddUpdateCommand;
> import org.apache.solr.update.processor.UpdateRequestProcessor;
> import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
>
> public class AddConditionalFieldsFactory extends
> UpdateRequestProcessorFactory
> {
> @Override
> public UpdateRequestProcessor getInstance(SolrQueryRequest req,
> SolrQueryResponse rsp, UpdateRequestProcessor next)
> {
> System.out.println("From customization:");
> return new AddConditionalFields(next);
> }
> }
>
> class AddConditionalFields extends UpdateRequestProcessor
> {
> public AddConditionalFields( UpdateRequestProcessor next) {
>
> super( next );
> }
>
> @Override
> public void processAdd(AddUpdateCommand cmd) throws IOException {
> SolrInputDocument doc = cmd.getSolrInputDocument();
>
> Object v = doc.getFieldValue( "url" );
> if( v != null ) {
> String url = v.toString();
> if( url.contains("question") ) {
> doc.addField( "tierFilter", "1" );
> }
> }
>
> // pass it up the chain
> super.processAdd(cmd);
> }
> }
>
> Here is my Java code-
> and I get the following error when I try to index-
> Aug 20, 2011 10:48:43 AM org.apache.solr.common.SolrException log
> SEVERE: java.lang.AbstractMethodError at
> org.apache.solr.update.processor.UpdateRequestProcessorChain.createProcessor(UpdateRequestProcessorChain.java:74)
> at
> org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:53)
>
>
> Any pointers please. I am using Solr 3.3
>
> Thanks,
> Bhawna
>
> On Thu, Aug 18, 2011 at 2:04 PM, simon <mt...@gmail.com> wrote:
>
>> An UpdateRequestProcessor would do the trick. Look at the (rather minimal)
>> documentation and code example in
>> http://wiki.apache.org/solr/UpdateRequestProcessor
>>
>> -Simon
>>
>> On Thu, Aug 18, 2011 at 4:15 PM, bhawna singh <si...@gmail.com>
>> wrote:
>>
>> > Hi All,
>> > I have a requirement to update a certain field value depending on the
>> field
>> > value of another field.
>> > To elaborate-
>> > I have a field called 'popularity' and a field called 'URL'. I need to
>> > assign popularity value depending on the domain (URL) ( I have the
>> > popularity and domain mapping in a text file).
>> >
>> > I am using CSVRequestHandler to import the data.
>> >
>> > What are the suggested ways to achieve this.
>> > Your quick response is much appreciated.
>> >
>> > Thanks,
>> > Bhawna
>> >
>>
>
Re: Update field value in the document based on value of another
field in the document
Posted by bhawna singh <si...@gmail.com>.
Now that I have set it up using UpdateProcessorChain, I am running into null
exeception.
Here is what I have-
In SolrConfig.xml
<updateRequestProcessorChain name="mychain" >
<processor class="mysolr.AddConditionalFieldsFactory" >
</processor>
<processor class="solr.RunUpdateProcessorFactory" />
<processor class="solr.LogUpdateProcessorFactory" />
</updateRequestProcessorChain>
<requestHandler name="/update/csv" class="solr.CSVRequestHandler"
startup="lazy" >
<lst name="defaults">
<str name="update.chain">mychain</str>
</lst>
</requestHandler>
Here is my java code-
package mysolr;
import java.io.IOException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
public class AddConditionalFieldsFactory extends
UpdateRequestProcessorFactory
{
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp, UpdateRequestProcessor next)
{
System.out.println("From customization:");
return new AddConditionalFields(next);
}
}
class AddConditionalFields extends UpdateRequestProcessor
{
public AddConditionalFields( UpdateRequestProcessor next) {
super( next );
}
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
SolrInputDocument doc = cmd.getSolrInputDocument();
Object v = doc.getFieldValue( "url" );
if( v != null ) {
String url = v.toString();
if( url.contains("question") ) {
doc.addField( "tierFilter", "1" );
}
}
// pass it up the chain
super.processAdd(cmd);
}
}
Here is my Java code-
and I get the following error when I try to index-
Aug 20, 2011 10:48:43 AM org.apache.solr.common.SolrException log
SEVERE: java.lang.AbstractMethodError at
org.apache.solr.update.processor.UpdateRequestProcessorChain.createProcessor(UpdateRequestProcessorChain.java:74)
at
org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:53)
Any pointers please. I am using Solr 3.3
Thanks,
Bhawna
On Thu, Aug 18, 2011 at 2:04 PM, simon <mt...@gmail.com> wrote:
> An UpdateRequestProcessor would do the trick. Look at the (rather minimal)
> documentation and code example in
> http://wiki.apache.org/solr/UpdateRequestProcessor
>
> -Simon
>
> On Thu, Aug 18, 2011 at 4:15 PM, bhawna singh <si...@gmail.com>
> wrote:
>
> > Hi All,
> > I have a requirement to update a certain field value depending on the
> field
> > value of another field.
> > To elaborate-
> > I have a field called 'popularity' and a field called 'URL'. I need to
> > assign popularity value depending on the domain (URL) ( I have the
> > popularity and domain mapping in a text file).
> >
> > I am using CSVRequestHandler to import the data.
> >
> > What are the suggested ways to achieve this.
> > Your quick response is much appreciated.
> >
> > Thanks,
> > Bhawna
> >
>
Re: Update field value in the document based on value of another
field in the document
Posted by simon <mt...@gmail.com>.
An UpdateRequestProcessor would do the trick. Look at the (rather minimal)
documentation and code example in
http://wiki.apache.org/solr/UpdateRequestProcessor
-Simon
On Thu, Aug 18, 2011 at 4:15 PM, bhawna singh <si...@gmail.com> wrote:
> Hi All,
> I have a requirement to update a certain field value depending on the field
> value of another field.
> To elaborate-
> I have a field called 'popularity' and a field called 'URL'. I need to
> assign popularity value depending on the domain (URL) ( I have the
> popularity and domain mapping in a text file).
>
> I am using CSVRequestHandler to import the data.
>
> What are the suggested ways to achieve this.
> Your quick response is much appreciated.
>
> Thanks,
> Bhawna
>