lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Markus.Rietz...@rzf.fin-nrw.de>
Subject dataimporthandler and javascript transformer and default values
Date Mon, 14 Jun 2010 12:14:56 GMT
hi,

i have two questions:

1) how can i set a default value on an imported field if the
field/column is missing from a SQL query
2) i had a problem with the dataimporthandler. in one database column
(WebDst) i have a string with a comma/semicolon seperated numbers, like

	100,200; 300;400, 500

there can be a space or not. i want to have a multivalued field in the
end like

<arr name="__intern">
	<str>100</str>
	<str>200</str>
	<str>300</str>
	<str>400</str>
	<str>500</str>
</arr>

i thought that the javascript/script-transformer could do the trick. i
have a script like

 <script><![CDATA[
        function dst2intern(row) {
            var webdst='';
            var count = 0;
            webdst = row.get('WebDst');
            var arr = new java.util.ArrayList();
            if (webdst) {
                // var dst = webdst.split(/[,; ] */);
                var dst = webdst.split(';');
                for (var i=0; i<dst.length; i++) {
                    arr.add(dst[i]);
                    count++;
                }
                if (!count) {
                    arr.add('0');
                }
                row.put('intern', arr);
            } else {
                arr.add('0');
                row.put('intern', arr);
            }
            return row;
        }
    ]]></script>

in my entity-definition i have
transformer="RegexTransformer,script:dst2intern,TemplateTransformer"

and then i have a field __intern

 <field name="__intern" column="intern" />

i thought that this would work perfect. it seems the split only can
split on ; when comparing a single char.
the regex with 
	
	webdst.split(/[,; ] */);

doesn't work. i have check it in a simple html-page, there the
javascript split works with the regex.
the solution which works for me is to first use a regex transformer on
WebDst

<field name="WebDst" regex="[,; ] *" replaceWith=";" column="WebDst" />
<field name="__intern" column="intern" />

and use a simple ";" split in the javascript.

i am using solr 1.4, java 1.6...

does anyone know or can tell my, why the javascript split with a regex
doesn't work?

thank you

markus


 

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message