Changeset 6735


Ignore:
Timestamp:
2004-02-05T12:04:56+13:00 (20 years ago)
Author:
cs025
Message:

Added support for naming indexes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java

    r6696 r6735  
    108108  }
    109109   
    110   class CollectionIndexer
    111   { String level;
    112     String type;
    113     String name;
    114     List fields;
    115     String sort;
    116 
    117     public CollectionIndexer(String type, String indexName, Node node)
    118     { this.type = type.toLowerCase();
    119       this.fields = new ArrayList();
    120       this.name = indexName;
    121       this.level = IndexerManager.DEFAULT_LEVEL;
    122    
    123       NodeList children = node.getChildNodes();
    124       for (int c = 0; c < children.getLength(); c ++) {
    125     Node child = children.item(c);
    126    
    127     if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
    128       String name = child.getNodeName();
    129      
    130       if (name.equals("level")) {
    131         String levelName = DOMUtils.getNodeChildText(children.item(c));
    132         this.level = levelName;
    133       }
    134       else if (name.equals("field")) {
    135         String fieldName = DOMUtils.getNodeChildText(children.item(c));
    136         this.fields.add(fieldName.toString());
    137       }
    138     }
    139       }
    140       if (this.fields.size() == 0) {
    141     this.fields.add(IndexerManager.DEFAULT_FIELD);
    142       }
    143     }
    144 
    145     public void prepareIndexer(Map indexerMap)
    146     { IndexerInterface indexer = null;
    147 
    148       System.out.println("Index: " + this.type);
    149 
    150       if (!indexerMap.containsKey(this.type)) {
    151     if (this.type.toLowerCase().equals("mg")) {
    152       indexer = new MGIndexer();     
    153     }
    154     if (indexer != null) {
    155       indexerMap.put(this.type, indexer);
    156     }
    157       }
    158 
    159       indexer = (IndexerInterface) indexerMap.get(this.type);
    160       if (indexer != null) {
    161     indexer.addIndex(this.level, this.fields.get(0).toString());
    162       }
    163     }
    164   }
    165 
    166110  /**
    167111   *  Create the collection manager for a given collection
     
    255199      Document document = builder.parse(collectionConfig);
    256200
    257       Map                  indexerMap = new HashMap();
    258 
    259201      // TODO: report an error
    260202      if (document == null)
     
    282224    // the name is a plugin element
    283225    if (name.equals("search")) {
    284       NodeList indexChildren = children.item(c).getChildNodes();
    285 
    286       for (int i = 0; i < indexChildren.getLength(); i ++) {
    287         String childName = indexChildren.item(i).getNodeName();
    288 
    289         if (childName.equals("index"))
    290         { NamedNodeMap atts = indexChildren.item(i).getAttributes();
    291           Node attribute = atts.getNamedItem("type");
    292           String type = attribute.getNodeValue();
    293 
    294           attribute = atts.getNamedItem("name");
    295           String indexName = attribute.getNodeValue();
    296          
    297           // create the local indexer representation
    298           CollectionIndexer indexer = new CollectionIndexer(type, indexName, indexChildren.item(i));
    299          
    300           // prepare it...
    301           indexer.prepareIndexer(indexerMap);
    302         }
    303       }
     226      // pick up attributes from the <search> tag now...
     227      NamedNodeMap searchAttributes = children.item(c).getAttributes();
     228      Node searchAttribute = searchAttributes.getNamedItem("type");
     229      String searchType = searchAttribute.getNodeValue();
     230
     231      searchAttribute = searchAttributes.getNamedItem("name");
     232      String searchName = null;
     233
     234      if (searchAttribute != null) {
     235        searchName = searchAttribute.getNodeValue();
     236      }
     237
     238      // create the pertinent indexer...
     239      IndexerInterface indexer = IndexerFactory.makeIndexer(searchType, searchName);
     240
     241      if (indexer == null) {
     242        continue;
     243      }
     244
     245      // configure the indexer
     246      indexer.configure(children.item(c));
     247
     248      // install it into the build manager
     249      buildManager.addIndexer(indexer);
    304250    }
    305251    else if (name.equals("browse"))
     
    310256    {
    311257    }
    312       }
    313 
    314       Iterator indexers = indexerMap.values().iterator();
    315       while (indexers.hasNext()) {
    316     IndexerInterface indexer = (IndexerInterface) indexers.next();
    317 
    318     // attach the classifier
    319     buildManager.addIndexer(indexer);   
    320258      }
    321259    }
Note: See TracChangeset for help on using the changeset viewer.