lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joel Karlsson" <87.karls...@gmail.com>
Subject Re: Problem indexing on Oracle DB
Date Tue, 02 Dec 2008 08:08:52 GMT
Thanks for your reply!

I wrote such a transformer and now it seems to work perfectly. Here's the
code for the transformer if anyone encounters the same problem, or if anyone
want to improve it:

import org.apache.solr.handler.dataimport.*;
import oracle.sql.CLOB;
import java.util.*;
import java.io.*;

public class ClobTransformer extends Transformer
{
    public Map<String, Object> transformRow(Map<String, Object> row, Context
context)
    {
        List<Map<String, String>> fields = context.getAllEntityFields();
        for (Map<String, String> field : fields)
        {
            String toString = field.get("toString");
            if ("true".equals(toString))
            {
                String columnName = field.get("column");
                CLOB clob = (CLOB)row.get(columnName);
                if (clob != null)
                {
                    StringBuffer strOut = new StringBuffer();
                    String app;
                    try {
                    BufferedReader br = new
BufferedReader(clob.getCharacterStream());
                    while ((app=br.readLine())!=null)
                    strOut.append(app);
                    } catch (Exception e) { e.printStackTrace(); }

                    row.put(columnName, strOut.toString());
                }
            }
        }
        return row;

    }
}

// Joel

2008/12/2 Noble Paul നോബിള്‍ नोब्ळ् <noble.paul@gmail.com>

> Hi Joel,
> DIH does not translate Clob automatically to text.
>
> We can open that as an issue.
> meanwhile you can write a transformer of your own to read Clob and
> convert to text.
>
> http://wiki.apache.org/solr/DataImportHandler#head-4756038c418ab3fa389efc822277a7a789d27688
>
>
> On Tue, Dec 2, 2008 at 2:57 AM, Joel Karlsson <87.karlsson@gmail.com>
> wrote:
> > Thanks for your reply!
> >
> > I'm already using the DataImportHandler for indexing. Do I still have to
> > convert the Clob myself or are there any built-in functions that I've
> > missed?
> >
> > // Joel
> >
> >
> > 2008/12/1 Yonik Seeley <yonik@apache.org>
> >
> >> If you are querying Oracle yourself and using something like SolrJ,
> >> then you must convert the Clob yourself into a String representation.
> >>
> >> Also, did you look at Solr's DataImportHandler?
> >>
> >> -Yonik
> >>
> >> On Mon, Dec 1, 2008 at 3:11 PM, Joel Karlsson <87.karlsson@gmail.com>
> >> wrote:
> >> > Hello everyone,
> >> >
> >> > I'm trying to index on an Oracle DB, but can't seem to find any built
> in
> >> > support for objects of type oracle.sql.Clob. The field I try to put
> the
> >> data
> >> > into is of type text, but after indexing it only contains the
> >> Clob-objects
> >> > string representation, i.e. something like oracle.sql.Clob@12345.Anyone
> >> who
> >> > knows how to get Solr to index the content of these objects rather
> than
> >> its
> >> > string representation??
> >> >
> >> > Thanks in advance! // Joel
> >> >
> >>
> >
>
>
>
> --
> --Noble Paul
>
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message