Changeset 30691 for main/trunk/gli


Ignore:
Timestamp:
2016-08-08T13:47:54+12:00 (8 years ago)
Author:
kjdon
Message:

changed the way sort and facet elements are stored. they are currently not used by GLI, so don;t bother converting sort to Sort etc. Just copy them as is into solr element, then back out again later. Was just making up one displayItem per sort/facet. what happens if there are two or more?? now they will all be copied over. Also added in handling for sortDefault.

File:
1 edited

Legend:

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

    r30680 r30691  
    397397    }
    398398
    399         //This processes <sort> and <facet> subelements of <search> for a solr collection
    400     // Note that GLI at present does not allow the user to set or modify the solr-specific elements
    401     // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such
    402     // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.
     399  //This processes <sort> (lucene), or <sort> and <facet> (solr) subelements of <search> also <defaultSort>
     400  // Note that GLI at present does not allow the user to set or modify these.
     401  // This function, and its inverse convertSolrFacetsAndSorts, are only here to preserve such elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.
     402  // it just copies them into storage.
    403403    static private void doSolrFacetsAndSorts(Document to, Node searchNode)
    404404    {
     
    410410
    411411        NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR);//<sort>
     412       
    412413        int num_nodes = sort_children.getLength();
    413414
    414         for (int i = 0; i < num_nodes; i++)
    415         {
    416 
    417             Element sort_element = to.createElement(StaticStrings.SORT_ELEMENT);//<Sort>
    418             Element e = (Element) sort_children.item(i);
    419             String sort_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    420             String sort_str_display = sort_str;//for creating collectionmetadata for this sort element
    421 
    422             // Handling 'sort' element
    423             sort_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, sort_str);
    424            
    425             Element displayItem = (Element) XMLTools.getChildByTagName(e, StaticStrings.DISPLAYITEM_STR); // gets the first <displayItem> child of <sort>
    426 
    427             if(displayItem != null) {
    428 
    429                 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    430 
    431                 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);       
    432                 String value_str = XMLTools.getNodeText(displayItem);
    433 
    434                 String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);
    435                 String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
    436 
    437                 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_ELEMENT); // <DisplayItem> not <displayItem>!
    438                 displayItem_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
    439                 if (name_str != null && !name_str.equals(""))
    440                 {
    441                     displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
    442                 }
    443 
    444                     if (lang_str != null && !lang_str.equals(""))
    445                 {
    446                     displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
    447                 }
    448                 if (value_str != null && !value_str.equals(""))
    449                 {
    450                     //XMLTools.setNodeText(displayItem_element, value_str);
    451                     displayItem_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str);
    452                 }
    453 
    454                 if (!key_str.equals(""))
    455                 {
    456                     displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
    457                 }
    458                 if (!dictionary_str.equals(""))
    459                 {
    460                     displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary_str);
    461                 }
    462 
    463                 sort_element.appendChild(displayItem_element);
    464 
    465             }
    466 
    467             solr_element.appendChild(sort_element);
    468 
    469             sort_element = null;
    470 
    471             // Handling 'displayItem' element of this 'sort' element
    472             // 'e' is the parent 'sort' element of 'displayItem' element
    473             ///ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, sort_str_display);
    474             ///appendArrayList(toElement, collectionmetadata_list);
    475 
    476         } // for loop on sort elements ends
    477 
     415        for (int i = 0; i < num_nodes; i++) {
     416          solr_element.appendChild(to.importNode((Element) sort_children.item(i), true));
     417        }
     418        Element sort_def = (Element)XMLTools.getChildByTagName(searchNode, StaticStrings.SORT_DEFAULT_ELEMENT);
     419        if (sort_def != null) {
     420          solr_element.appendChild(to.importNode(sort_def, true));
     421        }
    478422
    479423        NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR);//facet
     
    482426        for (int i = 0; i < num_nodes; i++)
    483427        {
    484 
    485             Element facet_element = to.createElement(StaticStrings.FACET_ELEMENT);//<Facet>
    486             Element e = (Element) facet_children.item(i);
    487             String facet_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    488             String facet_str_display = facet_str;//for creating collectionmetadata for this facet
    489 
    490             // Handling 'facet' element
    491             facet_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, facet_str);
    492            
    493             Element displayItem = (Element) XMLTools.getChildByTagName(e, StaticStrings.DISPLAYITEM_STR); // gets the first <displayItem> child of <sort>
    494 
    495             if(displayItem != null) {
    496                 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    497 
    498                 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);
    499                 String value_str = XMLTools.getNodeText(displayItem);
    500                
    501                 String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);
    502                 String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
    503 
    504                 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_ELEMENT); // <DisplayItem> not <displayItem>!
    505                 displayItem_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
    506                
    507                 if (name_str != null && !name_str.equals(""))
    508                 {
    509                     displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
    510                 }
    511 
    512                     if (lang_str != null && !lang_str.equals(""))
    513                 {
    514                     displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
    515                 }
    516                 if (value_str != null && !value_str.equals(""))
    517                 {
    518                     //XMLTools.setNodeText(displayItem_element, value_str);
    519                     displayItem_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str);
    520                 }
    521 
    522                 if (!key_str.equals(""))
    523                 {
    524                     displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
    525                 }
    526                 if (!dictionary_str.equals(""))
    527                 {
    528                     displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary_str);
    529                 }
    530                 facet_element.appendChild(displayItem_element);
    531 
    532             }
    533             solr_element.appendChild(facet_element);
    534 
    535             facet_element = null;
    536 
    537             // Handling 'displayItem' element of this 'facet' element
    538             // 'e' is the parent 'facet' element of 'displayItem' element
    539             ///ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, facet_str_display);
    540             ///appendArrayList(toElement, collectionmetadata_list);
    541 
    542         } // for loop on facet elements ends
     428          solr_element.appendChild(to.importNode((Element) facet_children.item(i), true));
     429        }
    543430
    544431        // finished processing sort and facet elements
    545432        toElement.appendChild(solr_element);
    546433
     434   
    547435    }
    548436
     
    23362224    }
    23372225
    2338         //convert <facet> and <sort> elements and their displayItem subelements,
     2226        //convert <facet> and <sort> and <defaultSort> elements
    23392227        //which go in 'search' element in collectionConfig.xml
    23402228    //parameter 'to' is the document to be saved as collectionConfig.xml
    23412229    //parameter 'from' is the internal xml structure
     2230  // for lucene and solr collections
     2231  // just a straight copy at present
    23422232    // Note that GLI at present does not allow the user to set or modify the solr-specific elements
    2343     // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such
     2233    // <sort> and <facet>. This function, and its inverse doSolrFacetsAndSorts, is only here to preserve such
    23442234    // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.
    23452235    static private void convertSolrFacetsAndSorts(Document from, Document to)
     
    23492239        Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR);
    23502240
    2351         //There are two sets of <Solr> elements, find the one which is assigned 'true'
     2241        //There are two sets of <Solr> elements, find the one which is assigned 'true'   ---  is this true???
    23522242        Element solr = XMLTools.getNamedElement(source, StaticStrings.SOLR_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
    23532243        if (solr == null)
    23542244        {
    2355             return;
    2356         }
    2357         NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_ELEMENT); //<Sort>
     2245          return;
     2246        }
     2247        NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_LOW_STR);
    23582248        int sort_elements_length = sort_elements.getLength();
    2359         NodeList facet_elements = solr.getElementsByTagName(StaticStrings.FACET_ELEMENT); //<Facet>
     2249
     2250        for (int j = 0; j < sort_elements_length; j++)
     2251        {
     2252          Element sort_ele = (Element) sort_elements.item(j);
     2253          search.appendChild(to.importNode(sort_ele, true));
     2254        }
     2255        Element sort_def = (Element)XMLTools.getChildByTagName(solr, StaticStrings.SORT_DEFAULT_ELEMENT);
     2256        if (sort_def != null) {
     2257          search.appendChild(to.importNode(sort_def, true));
     2258        }
     2259        NodeList facet_elements = solr.getElementsByTagName(StaticStrings.FACET_LOW_STR);
    23602260        int facet_elements_length = facet_elements.getLength();
    2361 
    2362         for (int j = 0; j < sort_elements_length; j++)
    2363         {
    2364             Element sort_element = (Element) sort_elements.item(j);
    2365             if (sort_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR))
    2366             {
    2367                 continue;
    2368             }
    2369 
    2370             Element sort_ele = to.createElement(StaticStrings.SORT_LOW_STR);//<sort>
    2371             String name_attr = sort_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    2372 
    2373             /*if (name_attr.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_attr.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1)
    2374                 {
    2375                 name_attr = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length());
    2376                 }
    2377             */
    2378             sort_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_attr);
    2379 
    2380             // Now constructing 'displayItem' element for this 'sort_ele' element
    2381             Element displayItem = (Element) XMLTools.getChildByTagName(sort_element, StaticStrings.DISPLAYITEM_ELEMENT); // gets the first <DisplayItem> (not <displayItem>!) child of <Sort>
    2382 
    2383             if(displayItem != null) {
    2384                 if (displayItem.hasAttribute(StaticStrings.ASSIGNED_ATTRIBUTE) && displayItem.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR)) {
    2385                 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_STR);//<displayItem>
    2386                
    2387                 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    2388 
    2389                 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);   
    2390                 String value_str = displayItem.getAttribute(StaticStrings.VALUE_ATTRIBUTE);
    2391 
    2392                 String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);
    2393                 String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
    2394 
    2395                 if (name_str != null && !name_str.equals(""))
    2396                     {
    2397                     displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
    2398                     }
    2399                
    2400                 if (lang_str != null && !lang_str.equals(""))
    2401                     {
    2402                     displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
    2403                     }
    2404                 if (value_str != null && !value_str.equals(""))
    2405                     {
    2406                     XMLTools.setNodeText(displayItem_element, value_str);
    2407                     }
    2408 
    2409                 if(!key_str.equals("")) {
    2410                     displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
    2411                 }
    2412                 if(!dictionary_str.equals("")) {
    2413                     displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, key_str);
    2414                 }
    2415 
    2416                 sort_ele.appendChild(displayItem_element);
    2417                 }
    2418             }
    2419 
    2420             search.appendChild(sort_ele);
    2421 
    2422         } //for loop on sort_elements ends
    2423 
    24242261        for (int j = 0; j < facet_elements_length; j++)
    2425         {
    2426             Element facet_element = (Element) facet_elements.item(j);
    2427             if (facet_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR))
    2428             {
    2429                 continue;
    2430             }
    2431 
    2432             Element facet_ele = to.createElement(StaticStrings.FACET_LOW_STR);//<facet>
    2433             String name_attr = facet_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    2434 
    2435             facet_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_attr);
    2436 
    2437             // Now constructing 'displayItem' element for this 'facet_ele' element
    2438             Element displayItem = (Element) XMLTools.getChildByTagName(facet_element, StaticStrings.DISPLAYITEM_ELEMENT); // gets the first <DisplayItem> (not <displayItem>!) child of <Facet>
    2439            
    2440             if(displayItem != null) {
    2441                 if (displayItem.hasAttribute(StaticStrings.ASSIGNED_ATTRIBUTE) && displayItem.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR)) {
    2442                 Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_STR);//<displayItem>
    2443 
    2444                 String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    2445                
    2446                 String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);
    2447                 String value_str = displayItem.getAttribute(StaticStrings.VALUE_ATTRIBUTE);
    2448 
    2449                 String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);
    2450                 String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
    2451 
    2452                 if (lang_str != null && !lang_str.equals(""))
    2453                     {
    2454                     displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
    2455                     }
    2456                 if (name_str != null && !name_str.equals(""))
    2457                     {
    2458                     displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
    2459                     }
    2460                 if (value_str != null && !value_str.equals(""))
    2461                 {
    2462                     XMLTools.setNodeText(displayItem_element, value_str);                   
    2463                 }
    2464 
    2465                 if(!key_str.equals("")) {
    2466                     displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
    2467                 }
    2468                 if(!dictionary_str.equals("")) {
    2469                     displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, key_str);
    2470                 }
    2471                 facet_ele.appendChild(displayItem_element);
    2472                 }
    2473             }
    2474 
    2475             search.appendChild(facet_ele);
    2476 
    2477         } //for loop on facet_elements ends
    2478 
    2479     }
     2262          {
     2263            Element facet_ele = (Element) facet_elements.item(j);
     2264            search.appendChild(to.importNode(facet_ele, true));
     2265          }
     2266
     2267   
     2268    }
     2269
    24802270
    24812271    // Convert levels for mgpp/lucene. This method is called by converIndex() when mgpp indexer is detected.
Note: See TracChangeset for help on using the changeset viewer.