From: Michael L. <mi...@la...> - 2013-08-31 09:52:42
|
I am building an index with data from various sources. Unfortunately some of them have the same kind of IDs in 001 i.e. just numbers counting from 1 to whatever. To make them unique I would like to add a prefix to them, like 'XY12345' and 'AB12345' respectively for the '12345'-ids of the two sources. Is there an easy way to do this? I searched the solrmarc doku but the best I could find was to write a custom beanshell script. Is there perhaps an easier way? After all it is a simple concatination. -Michael |
From: Al R. <ala...@mn...> - 2013-09-02 23:52:58
|
Hello Michael, The beanshell script is pretty simple and is called using this configuration: id = script(getID.bsh), getPrefixId(<string>) putting in what you want for string. This is the beanshell script(there might be a couple of extra imports because I have other functions in the script) import org.marc4j.marc.Record; import org.marc4j.marc.ControlField; import org.marc4j.marc.DataField; import org.marc4j.marc.Subfield; import org.solrmarc.marc.MarcImporter; import org.solrmarc.tools.Utils; import org.solrmarc.tools.Utils; import java.io.FileWriter; import java.io.IOException; addClassPath("../import"); org.solrmarc.index.SolrIndexer indexer = null; /** * Get the ID and append the given string * @param Record * @return String - ID or null */ public String getPrefixId(Record record, String prefix) { DataField field; ControlField idField; String id; idField = (ControlField) record.getVariableField("001"); if (idField != null) { id = idField.getData(); System.out.println("We have an id of: " + id ); id = prefix + id; } else { return null; } return id; } Hope that helps -- al On 08/31/2013 04:28 AM, Michael Lackhoff wrote: > I am building an index with data from various sources. Unfortunately > some of them have the same kind of IDs in 001 i.e. just numbers counting > from 1 to whatever. To make them unique I would like to add a prefix to > them, like 'XY12345' and 'AB12345' respectively for the '12345'-ids of > the two sources. > Is there an easy way to do this? I searched the solrmarc doku but the > best I could find was to write a custom beanshell script. Is there > perhaps an easier way? After all it is a simple concatination. > > -Michael > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > VuFind-General mailing list > VuF...@li... > https://lists.sourceforge.net/lists/listinfo/vufind-general |
From: Michael L. <mi...@la...> - 2013-09-03 07:20:53
|
Hello Al, > The beanshell script is pretty simple and is called using this > configuration: > > id = script(getID.bsh), getPrefixId(<string>) > > putting in what you want for string. This is the beanshell script(there > might be a couple of extra imports because I have other functions in the > script) [...] Thanks, your script is very much what I came up with myself and it is working well. I just wanted to know if there is a builtin function which could keep maintanance down a bit (one line versus one line plus a script). I thought it is a common enough task. But to be future proof I still have a question: It might be that I want the id to come from a different field, like 015 or one of the other ID fields. Can I also pass the result of a normal field definition to a script, something like: id = script(getID.bsh), getPrefixId("015a first", DNB) to pass the DNB-ID and the string 'DNB' to the script? The script would then just concatinate the two parameters. public String getPrefixId(Record record, String id, String prefix) { return prefix + id; } Is this (or something similar) possible? As I said, for the moment the hard coded 001 is all I need but we all know how fast requirements keep changing... -Michael |
From: Alan R. <ala...@mn...> - 2013-09-03 13:22:50
|
Hello Michael, You would have to test that one. I just add additional functions and give them different names, leaving the field hard-coded. I do have 1 or 2, but I just cut, pasted, and edited. al On 09/03/2013 02:20 AM, Michael Lackhoff wrote: > Hello Al, > >> The beanshell script is pretty simple and is called using this >> configuration: >> >> id = script(getID.bsh), getPrefixId(<string>) >> >> putting in what you want for string. This is the beanshell script(there >> might be a couple of extra imports because I have other functions in the >> script) > [...] > > Thanks, your script is very much what I came up with myself and it is > working well. I just wanted to know if there is a builtin function which > could keep maintanance down a bit (one line versus one line plus a > script). I thought it is a common enough task. > > But to be future proof I still have a question: > It might be that I want the id to come from a different field, like 015 > or one of the other ID fields. Can I also pass the result of a normal > field definition to a script, something like: > > id = script(getID.bsh), getPrefixId("015a first", DNB) > > to pass the DNB-ID and the string 'DNB' to the script? The script would > then just concatinate the two parameters. > > public String getPrefixId(Record record, String id, String prefix) { > return prefix + id; > } > > Is this (or something similar) possible? > As I said, for the moment the hard coded 001 is all I need but we all > know how fast requirements keep changing... > > -Michael > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > VuFind-General mailing list > VuF...@li... > https://lists.sourceforge.net/lists/listinfo/vufind-general -- Alan Rykhus PALS, A Program of the Minnesota State Colleges and Universities (507)389-1975 ala...@mn... "Be pleasant until ten o'clock in the morning and the rest of the day will take care of itself." ~ Elbert Hubbard |
From: Demian K. <dem...@vi...> - 2013-09-03 12:40:05
|
> But to be future proof I still have a question: > It might be that I want the id to come from a different field, like 015 > or one of the other ID fields. Can I also pass the result of a normal > field definition to a script, something like: > > id = script(getID.bsh), getPrefixId("015a first", DNB) > > to pass the DNB-ID and the string 'DNB' to the script? The script would > then just concatinate the two parameters. > > public String getPrefixId(Record record, String id, String prefix) { > return prefix + id; > } > > Is this (or something similar) possible? > As I said, for the moment the hard coded 001 is all I need but we all > know how fast requirements keep changing... I don't think there's a simple way to do this in a script, but I'm copying to solrmarc-tech in case somebody there can correct me! Of course, the translation-map/regex solution I mentioned could probably work for you here. - Demian |
From: Tod O. <to...@uc...> - 2013-09-03 13:42:45
|
This is completely untested, but you could try something akin to: // define the base level indexer so that its methods can be called from the script. // note that the SolrIndexer code will set this value before the script methods are called. org.solrmarc.index.SolrIndexer indexer = null; public String getPrexfixId(Record rec, String prefix, String fieldSpec) { String id = indexer.getFirstFieldVal(rec, fieldSpec); return prefix + id; } You'd need to add error checking, of course. And see the javadoc for org.solrmarc.index.SolrIndexer. But then you get to specify both the prefix as well as the field for the ID in the properties file. If this is really useful, working it up in java and contributing to solrmarc would be nice. -Tod On Sep 3, 2013, at 7:39 AM, Demian Katz <dem...@vi...> wrote: >> But to be future proof I still have a question: >> It might be that I want the id to come from a different field, like 015 >> or one of the other ID fields. Can I also pass the result of a normal >> field definition to a script, something like: >> >> id = script(getID.bsh), getPrefixId("015a first", DNB) >> >> to pass the DNB-ID and the string 'DNB' to the script? The script would >> then just concatinate the two parameters. >> >> public String getPrefixId(Record record, String id, String prefix) { >> return prefix + id; >> } >> >> Is this (or something similar) possible? >> As I said, for the moment the hard coded 001 is all I need but we all >> know how fast requirements keep changing... > > I don't think there's a simple way to do this in a script, but I'm copying to solrmarc-tech in case somebody there can correct me! > > Of course, the translation-map/regex solution I mentioned could probably work for you here. > > - Demian > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > VuFind-General mailing list > VuF...@li... > https://lists.sourceforge.net/lists/listinfo/vufind-general |
From: Tod O. <ols...@gm...> - 2013-09-03 13:45:53
|
This is completely untested, but you could try something akin to: // define the base level indexer so that its methods can be called from the script. // note that the SolrIndexer code will set this value before the script methods are called. org.solrmarc.index.SolrIndexer indexer = null; public String getPrexfixId(Record rec, String prefix, String fieldSpec) { String id = indexer.getFirstFieldVal(rec, fieldSpec); return prefix + id; } You'd need to add error checking, of course. And see the javadoc for org.solrmarc.index.SolrIndexer. But then you get to specify both the prefix as well as the field for the ID in the properties file. If this is really useful, working it up in java and contributing to solrmarc would be nice. -Tod On Sep 3, 2013, at 7:39 AM, Demian Katz <dem...@vi...> wrote: >> But to be future proof I still have a question: >> It might be that I want the id to come from a different field, like 015 >> or one of the other ID fields. Can I also pass the result of a normal >> field definition to a script, something like: >> >> id = script(getID.bsh), getPrefixId("015a first", DNB) >> >> to pass the DNB-ID and the string 'DNB' to the script? The script would >> then just concatinate the two parameters. >> >> public String getPrefixId(Record record, String id, String prefix) { >> return prefix + id; >> } >> >> Is this (or something similar) possible? >> As I said, for the moment the hard coded 001 is all I need but we all >> know how fast requirements keep changing... > > I don't think there's a simple way to do this in a script, but I'm copying to solrmarc-tech in case somebody there can correct me! > > Of course, the translation-map/regex solution I mentioned could probably work for you here. > > - Demian > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > VuFind-General mailing list > VuF...@li... > https://lists.sourceforge.net/lists/listinfo/vufind-general |
From: Michael L. <mi...@la...> - 2013-09-03 15:32:28
|
Hello Al, Demian, Tod and Uwe, many thanks for your suggestions. It really looks like there are a lot of good options. I will archive your answers and I am very confident that I will be able to find a solution whenever the need arises. I find it particular useful to have very different approaches at hand. That way the learning effect is best. Thanks again and best wishes -Michael |