Fwd: bug in VuFindIndexer for fullXXX fields ... and a fix

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: bug in VuFindIndexer for fullXXX fields ... and a fix

Naomi Dushay
Andrew,

just want to make sure you saw this.  The getAllSubfields() method, as of  v127, only gets the *first* of the marc fields indicated by the tag.  I believe the intent may have been to cycle through *all* of the marc fields matching the tags.  

This affects the following VuFind fields:

fullTopic
fullGenre
fullGeographic
fullTitle


Patch :

Index: src/org/solrmarc/index/VuFindIndexer.java
===================================================================
--- src/org/solrmarc/index/VuFindIndexer.java (revision 699)
+++ src/org/solrmarc/index/VuFindIndexer.java (working copy)
@@ -275,31 +275,30 @@
  * @param marcFieldNum - the marc field number as a string (e.g. "245")
  * @return
  */
- public Set<String> getAllSubfields(final Record record, String marcFieldNum)
- {
- Set<String> result = new LinkedHashSet<String>();
-
-        StringBuffer buffer = new StringBuffer("");
-
- DataField marcField = (DataField) record.getVariableField(marcFieldNum);
- if (marcField != null) {
- List<Subfield> subfields = marcField.getSubfields();
- Iterator<Subfield> iter = subfields.iterator();
+    public Set<String> getAllSubfields(final Record record, String marcFieldNum)
+    {
+        Set<String> result = new LinkedHashSet<String>();
 
- Subfield subfield;
 
- while (iter.hasNext()) {
- subfield = iter.next();
-                if (buffer.length() > 0) {
-                    buffer.append(" " + subfield.getData());
-                } else {
-                    buffer.append(subfield.getData());
- }
- }
-            result.add(buffer.toString());
+ List<VariableField> marcFields = record.getVariableFields(marcFieldNum);
+        for (VariableField vf : marcFields) {
+            StringBuffer buffer = new StringBuffer("");
+    DataField df = (DataField) vf;
+        if (df != null) {
+     List<Subfield> subfields = df.getSubfields();
+            for (Subfield sf : subfields) {
+                    if (buffer.length() > 0) {
+                        buffer.append(" " + sf.getData());
+                    } else {
+                        buffer.append(sf.getData());
+        }
+            }
+        }
+        if (buffer.length() > 0)
+                result.add(buffer.toString());
         }
 
- return result;
+        return result;
     }
 
  /**


- Naomi

Begin forwarded message:

From: Naomi Dushay <[hidden email]>
Date: August 22, 2008 4:15:10 PM PDT
Subject: bug in VuFindIndexer for fullXXX fields ... and a fix
Reply-To: [hidden email]

The getAllSubfields() method, as of  v127, only gets the *first* of the marc fields indicated by the tag.  I believe the intent may have been to cycle through *all* of the marc fields matching the tags.  

This affects the following VuFind fields:

fullTopic
fullGenre
fullGeographic
fullTitle


Original version of method:

    public Set<String> getAllSubfields(final Record record, String marcFieldNum)
    {
        Set<String> result = new LinkedHashSet<String>();

        StringBuffer buffer = new StringBuffer("");

        DataField marcField = (DataField) record.getVariableField(marcFieldNum);
        if (marcField != null) {
            List<Subfield> subfields = marcField.getSubfields();
            Iterator<Subfield> iter = subfields.iterator();

            Subfield subfield;

            while (iter.hasNext()) {
               subfield = iter.next();
                if (buffer.length() > 0) {
                    buffer.append(" " + subfield.getData());
                } else {
                    buffer.append(subfield.getData());
                }
            }
            result.add(buffer.toString());
        }

        return result;
    }


Fixed method:

    public Set<String> getAllSubfields(final Record record, String marcFieldNum)
    {
        Set<String> result = new LinkedHashSet<String>();


List<VariableField> marcFields = record.getVariableFields(marcFieldNum);
        for (VariableField vf : marcFields) {
            StringBuffer buffer = new StringBuffer("");
    DataField df = (DataField) vf;
        if (df != null) {
    List<Subfield> subfields = df.getSubfields();
            for (Subfield sf : subfields) {
                    if (buffer.length() > 0) {
                        buffer.append(" " + sf.getData());
                    } else {
                        buffer.append(sf.getData());
        }
            }
        }
        if (buffer.length() > 0)
                result.add(buffer.toString());
        }

        return result;
    }

Fix that uses an array of tags:

    /**
     * For each occurrence of a marc field in the tags list, extract all 
     * subfield data from the field, place it in a single string (individual 
     * subfield data separated by spaces) and add the string to the result set.
     */
    @SuppressWarnings("unchecked")
public static final Set<String> getAllSubfields(final Record record, String[] tags) 
    {
Set<String> result = new LinkedHashSet<String>();

List<VariableField> varFlds = record.getVariableFields(tags);
        for (VariableField vf : varFlds) {
        
            StringBuffer buffer = new StringBuffer(500);

            DataField df = (DataField) vf;
    if (df != null) {
    List<Subfield> subfields = df.getSubfields();
            for (Subfield sf : subfields) {
                    if (buffer.length() > 0) {
                        buffer.append(" " + sf.getData());
                    } else {
                        buffer.append(sf.getData());
    }
            }
    }
    if (buffer.length() > 0)
                result.add(buffer.toString());
        }
        
        return result;
    }



This method also might live in org.solrmarc.tools.Utils , no?

(Sorry - I'm not able to give you  a patch at this time )



Naomi Dushay




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "solrmarc-tech" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/solrmarc-tech?hl=en
-~----------~----~----~----~------~----~------~--~---


Naomi Dushay




-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vufind-tech mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-tech
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: bug in VuFindIndexer for fullXXX fields ... and a fix

Andrew Nagy-2

Naomi - this was fixed a while back in the solrmarc SVN.

 

Andrew

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Naomi Dushay
Sent: Wednesday, August 27, 2008 10:54 AM
To: [hidden email]
Subject: [VuFind-Tech] Fwd: bug in VuFindIndexer for fullXXX fields ... and a fix

 

Andrew,

 

just want to make sure you saw this.  The getAllSubfields() method, as of  v127, only gets the *first* of the marc fields indicated by the tag.  I believe the intent may have been to cycle through *all* of the marc fields matching the tags.  

 

This affects the following VuFind fields:

 

fullTopic

fullGenre

fullGeographic

fullTitle

 

 

Patch :

 

Index: src/org/solrmarc/index/VuFindIndexer.java

===================================================================

--- src/org/solrmarc/index/VuFindIndexer.java         (revision 699)

+++ src/org/solrmarc/index/VuFindIndexer.java      (working copy)

@@ -275,31 +275,30 @@

          * @param marcFieldNum - the marc field number as a string (e.g. "245")

          * @return

          */

-         public Set<String> getAllSubfields(final Record record, String marcFieldNum)

-         {

-                     Set<String> result = new LinkedHashSet<String>();

-

-        StringBuffer buffer = new StringBuffer("");

-

-                     DataField marcField = (DataField) record.getVariableField(marcFieldNum);

-                     if (marcField != null) {

-                                 List<Subfield> subfields = marcField.getSubfields();

-                                 Iterator<Subfield> iter = subfields.iterator();

+    public Set<String> getAllSubfields(final Record record, String marcFieldNum)

+    {

+        Set<String> result = new LinkedHashSet<String>();

 

-                                 Subfield subfield;

 

-                                 while (iter.hasNext()) {

-                                             subfield = iter.next();

-                if (buffer.length() > 0) {

-                    buffer.append(" " + subfield.getData());

-                } else {

-                    buffer.append(subfield.getData());

-                                             }

-                                 }

-            result.add(buffer.toString());

+        List<VariableField> marcFields = record.getVariableFields(marcFieldNum);

+        for (VariableField vf : marcFields) {

+            StringBuffer buffer = new StringBuffer("");

+           DataField df = (DataField) vf;

+           if (df != null) {

+                    List<Subfield> subfields = df.getSubfields();

+               for (Subfield sf : subfields) {

+                    if (buffer.length() > 0) {

+                        buffer.append(" " + sf.getData());

+                    } else {

+                        buffer.append(sf.getData());

+                       }

+               }

+           }

+           if (buffer.length() > 0)

+                result.add(buffer.toString());

         }

 

-                     return result;

+        return result;

     }

 

          /**

 

 

- Naomi

 

Begin forwarded message:



From: Naomi Dushay <[hidden email]>

Date: August 22, 2008 4:15:10 PM PDT

Subject: bug in VuFindIndexer for fullXXX fields ... and a fix

Reply-To: [hidden email]

 

The getAllSubfields() method, as of  v127, only gets the *first* of the marc fields indicated by the tag.  I believe the intent may have been to cycle through *all* of the marc fields matching the tags.  

 

This affects the following VuFind fields:

 

fullTopic

fullGenre

fullGeographic

fullTitle

 

 

Original version of method:

 

    public Set<String> getAllSubfields(final Record record, String marcFieldNum)

    {

        Set<String> result = new LinkedHashSet<String>();

 

        StringBuffer buffer = new StringBuffer("");

 

        DataField marcField = (DataField) record.getVariableField(marcFieldNum);

        if (marcField != null) {

            List<Subfield> subfields = marcField.getSubfields();

            Iterator<Subfield> iter = subfields.iterator();

 

            Subfield subfield;

 

            while (iter.hasNext()) {

               subfield = iter.next();

                if (buffer.length() > 0) {

                    buffer.append(" " + subfield.getData());

                } else {

                    buffer.append(subfield.getData());

                }

            }

            result.add(buffer.toString());

        }

 

        return result;

    }

 

 

Fixed method:

 

    public Set<String> getAllSubfields(final Record record, String marcFieldNum)

    {

        Set<String> result = new LinkedHashSet<String>();

 

 

      List<VariableField> marcFields = record.getVariableFields(marcFieldNum);

        for (VariableField vf : marcFields) {

            StringBuffer buffer = new StringBuffer("");

          DataField df = (DataField) vf;

          if (df != null) {

             List<Subfield> subfields = df.getSubfields();

              for (Subfield sf : subfields) {

                    if (buffer.length() > 0) {

                        buffer.append(" " + sf.getData());

                    } else {

                        buffer.append(sf.getData());

                 }

              }

          }

          if (buffer.length() > 0)

                result.add(buffer.toString());

        }

 

        return result;

    }

 

Fix that uses an array of tags:

 

    /**

     * For each occurrence of a marc field in the tags list, extract all 

     * subfield data from the field, place it in a single string (individual 

     * subfield data separated by spaces) and add the string to the result set.

     */

    @SuppressWarnings("unchecked")

      public static final Set<String> getAllSubfields(final Record record, String[] tags) 

    {

             Set<String> result = new LinkedHashSet<String>();

 

             List<VariableField> varFlds = record.getVariableFields(tags);

        for (VariableField vf : varFlds) {

            

            StringBuffer buffer = new StringBuffer(500);

 

            DataField df = (DataField) vf;

             if (df != null) {

                    List<Subfield> subfields = df.getSubfields();

              for (Subfield sf : subfields) {

                    if (buffer.length() > 0) {

                        buffer.append(" " + sf.getData());

                    } else {

                        buffer.append(sf.getData());

                          }

              }

             }

             if (buffer.length() > 0)

                result.add(buffer.toString());

        }

        

        return result;

    }

 

 

 

This method also might live in org.solrmarc.tools.Utils , no?

 

(Sorry - I'm not able to give you  a patch at this time )

 

 

 

Naomi Dushay

 

 

 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "solrmarc-tech" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/solrmarc-tech?hl=en
-~----------~----~----~----~------~----~------~--~---

 

 

Naomi Dushay

 

 

 


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vufind-tech mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-tech
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: bug in VuFindIndexer for fullXXX fields ... and a fix

Andrew Nagy-2
In reply to this post by Naomi Dushay

Naomi - I apologize - I jumped the gun on this.  I had fixed this locally and implemented it locally but never checked in my fixes into solrmarc.  I just did so now.  I believe the fixes were already incorporated in with VuFind however.

 

Andrew

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Naomi Dushay
Sent: Wednesday, August 27, 2008 10:54 AM
To: [hidden email]
Subject: [VuFind-Tech] Fwd: bug in VuFindIndexer for fullXXX fields ... and a fix

 

Andrew,

 

just want to make sure you saw this.  The getAllSubfields() method, as of  v127, only gets the *first* of the marc fields indicated by the tag.  I believe the intent may have been to cycle through *all* of the marc fields matching the tags.  

 

This affects the following VuFind fields:

 

fullTopic

fullGenre

fullGeographic

fullTitle

 

 

Patch :

 

Index: src/org/solrmarc/index/VuFindIndexer.java

===================================================================

--- src/org/solrmarc/index/VuFindIndexer.java         (revision 699)

+++ src/org/solrmarc/index/VuFindIndexer.java      (working copy)

@@ -275,31 +275,30 @@

          * @param marcFieldNum - the marc field number as a string (e.g. "245")

          * @return

          */

-         public Set<String> getAllSubfields(final Record record, String marcFieldNum)

-         {

-                     Set<String> result = new LinkedHashSet<String>();

-

-        StringBuffer buffer = new StringBuffer("");

-

-                     DataField marcField = (DataField) record.getVariableField(marcFieldNum);

-                     if (marcField != null) {

-                                 List<Subfield> subfields = marcField.getSubfields();

-                                 Iterator<Subfield> iter = subfields.iterator();

+    public Set<String> getAllSubfields(final Record record, String marcFieldNum)

+    {

+        Set<String> result = new LinkedHashSet<String>();

 

-                                 Subfield subfield;

 

-                                 while (iter.hasNext()) {

-                                             subfield = iter.next();

-                if (buffer.length() > 0) {

-                    buffer.append(" " + subfield.getData());

-                } else {

-                    buffer.append(subfield.getData());

-                                             }

-                                 }

-            result.add(buffer.toString());

+        List<VariableField> marcFields = record.getVariableFields(marcFieldNum);

+        for (VariableField vf : marcFields) {

+            StringBuffer buffer = new StringBuffer("");

+           DataField df = (DataField) vf;

+           if (df != null) {

+                    List<Subfield> subfields = df.getSubfields();

+               for (Subfield sf : subfields) {

+                    if (buffer.length() > 0) {

+                        buffer.append(" " + sf.getData());

+                    } else {

+                        buffer.append(sf.getData());

+                       }

+               }

+           }

+           if (buffer.length() > 0)

+                result.add(buffer.toString());

         }

 

-                     return result;

+        return result;

     }

 

          /**

 

 

- Naomi

 

Begin forwarded message:



From: Naomi Dushay <[hidden email]>

Date: August 22, 2008 4:15:10 PM PDT

Subject: bug in VuFindIndexer for fullXXX fields ... and a fix

Reply-To: [hidden email]

 

The getAllSubfields() method, as of  v127, only gets the *first* of the marc fields indicated by the tag.  I believe the intent may have been to cycle through *all* of the marc fields matching the tags.  

 

This affects the following VuFind fields:

 

fullTopic

fullGenre

fullGeographic

fullTitle

 

 

Original version of method:

 

    public Set<String> getAllSubfields(final Record record, String marcFieldNum)

    {

        Set<String> result = new LinkedHashSet<String>();

 

        StringBuffer buffer = new StringBuffer("");

 

        DataField marcField = (DataField) record.getVariableField(marcFieldNum);

        if (marcField != null) {

            List<Subfield> subfields = marcField.getSubfields();

            Iterator<Subfield> iter = subfields.iterator();

 

            Subfield subfield;

 

            while (iter.hasNext()) {

               subfield = iter.next();

                if (buffer.length() > 0) {

                    buffer.append(" " + subfield.getData());

                } else {

                    buffer.append(subfield.getData());

                }

            }

            result.add(buffer.toString());

        }

 

        return result;

    }

 

 

Fixed method:

 

    public Set<String> getAllSubfields(final Record record, String marcFieldNum)

    {

        Set<String> result = new LinkedHashSet<String>();

 

 

      List<VariableField> marcFields = record.getVariableFields(marcFieldNum);

        for (VariableField vf : marcFields) {

            StringBuffer buffer = new StringBuffer("");

          DataField df = (DataField) vf;

          if (df != null) {

             List<Subfield> subfields = df.getSubfields();

              for (Subfield sf : subfields) {

                    if (buffer.length() > 0) {

                        buffer.append(" " + sf.getData());

                    } else {

                        buffer.append(sf.getData());

                 }

              }

          }

          if (buffer.length() > 0)

                result.add(buffer.toString());

        }

 

        return result;

    }

 

Fix that uses an array of tags:

 

    /**

     * For each occurrence of a marc field in the tags list, extract all 

     * subfield data from the field, place it in a single string (individual 

     * subfield data separated by spaces) and add the string to the result set.

     */

    @SuppressWarnings("unchecked")

      public static final Set<String> getAllSubfields(final Record record, String[] tags) 

    {

             Set<String> result = new LinkedHashSet<String>();

 

             List<VariableField> varFlds = record.getVariableFields(tags);

        for (VariableField vf : varFlds) {

            

            StringBuffer buffer = new StringBuffer(500);

 

            DataField df = (DataField) vf;

             if (df != null) {

                    List<Subfield> subfields = df.getSubfields();

              for (Subfield sf : subfields) {

                    if (buffer.length() > 0) {

                        buffer.append(" " + sf.getData());

                    } else {

                        buffer.append(sf.getData());

                          }

              }

             }

             if (buffer.length() > 0)

                result.add(buffer.toString());

        }

        

        return result;

    }

 

 

 

This method also might live in org.solrmarc.tools.Utils , no?

 

(Sorry - I'm not able to give you  a patch at this time )

 

 

 

Naomi Dushay

 

 

 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "solrmarc-tech" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/solrmarc-tech?hl=en
-~----------~----~----~----~------~----~------~--~---

 

 

Naomi Dushay

 

 

 


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vufind-tech mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-tech