Changeset 36138


Ignore:
Timestamp:
2022-04-12T11:04:26+12:00 (2 years ago)
Author:
kjdon
Message:

split Index into 2 classes - Index: for mgpp/lucene/solr indexes, and MGIndex, which inherits from Index, for MG indexes.

Location:
main/trunk/gli/src/org/greenstone/gatherer/cdm
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/cdm/Index.java

    r24367 r36138  
    3636import org.w3c.dom.*;
    3737
    38 /** This class encapsulates a single indexing pair.
     38/** This class encapsulates a single index. MGPP/Lucene/SOLR
     39 * Can be subclassed for Sort fields and facet fields
    3940 * @author John Thompson, Greenstone Digital Library, University of Waikato
    4041 * @version 2.3d
     
    4243public class Index
    4344    implements Comparable, DOMProxyListEntry {
    44     /** An values of items in the index level enumeration. */
    45     static protected final String LEVEL[] = {StaticStrings.DOCUMENT_STR,  StaticStrings.SECTION_STR, StaticStrings.PARAGRAPH_STR};
    46 
    47     private ArrayList sources = null;
    48     /** The level of this index (if old sckool MG). */
    49     private int level = -1;
     45
     46    protected ArrayList sources = null;
     47
    5048    /** The element this index is based upon. */
    51     private Element element = null;
     49    protected Element element = null;
     50    /** The name for our elements */
     51    protected String element_name = StaticStrings.INDEX_ELEMENT;
     52    /** The name for the default element */
     53    protected String default_element_name = StaticStrings.INDEX_DEFAULT_ELEMENT;
    5254    /** The unique, if cryptic, identifier of an index. */
    53     private String id = null;
     55    protected String id = null;
    5456
    5557    /** Default constructor, which should only be used during DOMProxyListModel creation. */
     
    6668    this.sources = sources;
    6769    // Create a new element
    68     this.element = CollectionConfiguration.createElement(StaticStrings.INDEX_ELEMENT);
     70    this.element = CollectionConfiguration.createElement(this.element_name);
    6971    // For each source add a content element
    7072    int size = sources.size();
     
    8587    }
    8688
    87     /** Constructor for a newly assigned index with specified level (old skool). */
    88     public Index(int level, ArrayList sources) {
    89     this(sources);
    90     this.level = level;
    91     element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, LEVEL[level]);
    92     }
    93 
    94     public Index(String level, ArrayList sources) {
    95     this(sources);
    96     for(int i = 0; i < LEVEL.length; i++) {
    97         if(LEVEL[i].equalsIgnoreCase(level)) {
    98         this.level = i;
    99         }
    100     }
    101     element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, LEVEL[this.level]);
    102     }
    103 
    10489    /** Method to compare two indexes.
    10590     * @param object The other index as an <strong>Object</strong>.
     
    130115    return element;
    131116    }
    132    
    133     /** Method to get the value of level.
    134      * @return the level as a int
    135      */
    136     public int getLevel() {
    137     if(level == -1 && element != null) {
    138         String level_str = element.getAttribute(StaticStrings.LEVEL_ATTRIBUTE);
    139         for(int i = 0; level == -1 && i < LEVEL.length; i++) {
    140         if(level_str.equals(LEVEL[i])) {
    141             level = i;
    142         }
    143         }
    144         level_str = null;
    145     }
    146     return level;
    147     }
    148117
    149118    public String getID() {
     
    153122    else if(id == null) {
    154123        StringBuffer id_buffer = new StringBuffer();
    155         // Write level information, if any.
    156         int level = getLevel();
    157         if(0 <= level && level < 3) {
    158         id_buffer.append(LEVEL[level]);
    159         id_buffer.append(StaticStrings.COLON_CHARACTER);
    160         }
    161124        // Write data information. Retrieve each of the content sources and add them in a comma separated list.
    162125        ArrayList sources = getSources();
     
    225188    public void setElement(Element element) {
    226189    this.element = element;
    227     this.level = -1;
    228190    this.id = null;
    229191    this.sources = null;
    230192    }
    231193
    232     /** Method to set the level of this index which can only be used for the default index.
    233      * @param new_level the new level as an int
    234      */
    235     public void setLevel(int new_level) {
    236     // System.err.println("SetLevel(" + new_level + ")");
    237     if(element != null && element.getNodeName().equals(StaticStrings.INDEX_DEFAULT_ELEMENT)) {
    238         if (0 <= new_level && new_level < 3) {
    239         element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, LEVEL[new_level]);
    240         } else {
    241         element.setAttribute(StaticStrings.LEVEL_ATTRIBUTE, "");
    242         }
    243         this.id = null; // Regenerate ID.
    244         this.level = new_level;
    245     }
    246     else {
    247         DebugStream.println("Error! Called setLevel() of index other than the default.");
    248     }
    249     }
    250 
    251194    /** Method to set the sources for this index which can only be used for the default index.
    252195     * @param sources an ArrayList of source names
    253196     */
    254197    public void setSources(ArrayList sources) {
    255     if(element != null && element.getNodeName().equals(StaticStrings.INDEX_DEFAULT_ELEMENT)) {
     198    if(element != null && element.getNodeName().equals(this.default_element_name)) {
    256199        // Erase old sources
    257200        XMLTools.clear(element);
     
    288231    StringBuffer text_buffer = new StringBuffer("");
    289232    // Generate language dependant id (include extracted metadata namespace)
    290     // Write level information, if any.
    291     int level = getLevel();
    292     if(0 <= level && level < 3) {
    293         text_buffer.append(LEVEL[level]);
    294         text_buffer.append(StaticStrings.COLON_CHARACTER);
    295     }
    296233    // Write data information. Retrieve each of the content sources and add them in a comma separated list.
    297234    ArrayList sources = getSources();
Note: See TracChangeset for help on using the changeset viewer.