Changeset 30691
- Timestamp:
- 2016-08-08T13:47:54+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
r30680 r30691 397 397 } 398 398 399 //This processes <sort> and <facet> subelements of <search> for a solr collection400 // Note that GLI at present does not allow the user to set or modify the solr-specific elements401 // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such402 // 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. 403 403 static private void doSolrFacetsAndSorts(Document to, Node searchNode) 404 404 { … … 410 410 411 411 NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR);//<sort> 412 412 413 int num_nodes = sort_children.getLength(); 413 414 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 } 478 422 479 423 NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR);//facet … … 482 426 for (int i = 0; i < num_nodes; i++) 483 427 { 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 } 543 430 544 431 // finished processing sort and facet elements 545 432 toElement.appendChild(solr_element); 546 433 434 547 435 } 548 436 … … 2336 2224 } 2337 2225 2338 //convert <facet> and <sort> elements and their displayItem subelements,2226 //convert <facet> and <sort> and <defaultSort> elements 2339 2227 //which go in 'search' element in collectionConfig.xml 2340 2228 //parameter 'to' is the document to be saved as collectionConfig.xml 2341 2229 //parameter 'from' is the internal xml structure 2230 // for lucene and solr collections 2231 // just a straight copy at present 2342 2232 // 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 such2233 // <sort> and <facet>. This function, and its inverse doSolrFacetsAndSorts, is only here to preserve such 2344 2234 // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there. 2345 2235 static private void convertSolrFacetsAndSorts(Document from, Document to) … … 2349 2239 Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR); 2350 2240 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??? 2352 2242 Element solr = XMLTools.getNamedElement(source, StaticStrings.SOLR_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR); 2353 2243 if (solr == null) 2354 2244 { 2355 2356 } 2357 NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_ ELEMENT); //<Sort>2245 return; 2246 } 2247 NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_LOW_STR); 2358 2248 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); 2360 2260 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' element2381 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 ends2423 2424 2261 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 2480 2270 2481 2271 // 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.