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 ahammad <ah...@gmail.com> on 2009/08/20 15:37:56 UTC

Adding a prefix to fields

Hello,

Is it possible to add a prefix to the data in a Solr field? For example,
right now, I have a field called "id" that gets data from a DB through the
DataImportHandler. The DB returns a 4-character string like "ag5f". Would it
be possible to add a prefix to the data that is received?

In this specific case, the data relates to articles. So effectively, if the
DB has "ag5f" as an ID, I want it to be stored as "Article_ag5f". Is there a
way to define a prefix of "Article_" for a certain field?

I am aware that this can be done by writing a transformer. I already have 4
transformers handling a multitude of other things, and I would prefer an
alternative...

Thanks
-- 
View this message in context: http://www.nabble.com/Adding-a-prefix-to-fields-tp25062226p25062226.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Adding a prefix to fields

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
On Thu, Aug 20, 2009 at 7:07 PM, ahammad <ah...@gmail.com> wrote:

>
> Hello,
>
> Is it possible to add a prefix to the data in a Solr field? For example,
> right now, I have a field called "id" that gets data from a DB through the
> DataImportHandler. The DB returns a 4-character string like "ag5f". Would
> it
> be possible to add a prefix to the data that is received?
>

Easiest way is to use TemplateTransformer. The field definition can look
like:

<field column="id" template="Article_${entity.id}" />

-- 
Regards,
Shalin Shekhar Mangar.

Re: Adding a prefix to fields

Posted by Andrew Clegg <an...@gmail.com>.


ahammad wrote:
> 
> Is it possible to add a prefix to the data in a Solr field? For example,
> right now, I have a field called "id" that gets data from a DB through the
> DataImportHandler. The DB returns a 4-character string like "ag5f". Would
> it be possible to add a prefix to the data that is received?
> 
> In this specific case, the data relates to articles. So effectively, if
> the DB has "ag5f" as an ID, I want it to be stored as "Article_ag5f". Is
> there a way to define a prefix of "Article_" for a certain field?
> 

I have exactly this situation and I just handle it by adding the prefixes in
the SQL query.

select 'Article_' || id as id
from articles
etc.

I wrap all these up as views and store them in the DB, so Solr just has to
select * from each view.

Andrew.

-- 
View this message in context: http://www.nabble.com/Adding-a-prefix-to-fields-tp25062226p25062356.html
Sent from the Solr - User mailing list archive at Nabble.com.