Changeset 32086


Ignore:
Timestamp:
2017-11-27T12:49:33+13:00 (4 years ago)
Author:
kjdon
Message:

added code to deal with storing any displayItems for the facets, then using those to return a displayItem with any resulting facet info for a query

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java

    r30564 r32086  
    7474
    7575    protected ArrayList<String> _facets = new ArrayList<String>();
     76  protected HashMap<String, Element> _facet_display_names = new HashMap<String, Element>();
    7677
    7778    public GS2SolrSearch()
     
    119120       
    120121        // Setting up facets
    121         // TODO - get these from build config, in case some haven't built
     122
     123        // the search element from collectionConfig
    122124        Element searchElem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
     125
     126        Document owner = info.getOwnerDocument();
     127        // for each facet in buildConfig
    123128        NodeList facet_list = info.getElementsByTagName("facet");
    124129        for (int i=0; i<facet_list.getLength(); i++) {
    125           _facets.add(((Element)facet_list.item(i)).getAttribute(GSXML.SHORTNAME_ATT));
     130          Element facet = (Element)facet_list.item(i);
     131          String shortname = facet.getAttribute(GSXML.SHORTNAME_ATT);
     132          _facets.add(shortname);
     133
     134          // now add any displayItems into the facet element
     135          // (which is stored as part of info), then we can add to
     136          // the result if needed
     137          String longname = facet.getAttribute(GSXML.NAME_ATT);
     138          Element config_facet = GSXML.getNamedElement(searchElem, "facet", GSXML.NAME_ATT, longname);
     139          if (config_facet != null) {
     140            NodeList display_items = config_facet.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
     141            for (int j=0; j<display_items.getLength(); j++) {
     142              Element e = (Element) display_items.item(j);
     143              facet.appendChild(owner.importNode(e, true));
     144            }
     145            _facet_display_names.put(shortname, facet);
     146
     147          }
     148             
    126149        }
    127150       
     
    457480    }
    458481
    459     protected ArrayList<FacetWrapper> getFacets(Object query_result)
     482  protected ArrayList<FacetWrapper> getFacets(Object query_result, String lang)
    460483    {
    461484        if (!(query_result instanceof SolrQueryResult))
     
    477500        {
    478501          SolrFacetWrapper wrap = new SolrFacetWrapper(facet);
    479           // String name = wrap.getName();
    480           // String display_name = "Poo";
    481           // wrap.setDisplayName(display_name);
    482            
     502          String fname = wrap.getName();
     503          String dname = getDisplayText(_facet_display_names.get(fname), GSXML.DISPLAY_TEXT_NAME, lang, "en", "metadata_names");
     504          wrap.setDisplayName(dname);           
    483505          newFacetList.add(wrap);
    484506        }
Note: See TracChangeset for help on using the changeset viewer.