Changeset 25863


Ignore:
Timestamp:
2012-06-28T13:05:27+12:00 (12 years ago)
Author:
sjm84
Message:

Some changes to enable facet searching

File:
1 edited

Legend:

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

    r25862 r25863  
    2121// Greenstone classes
    2222import java.io.File;
     23import java.util.ArrayList;
    2324import java.util.HashMap;
    2425import java.util.Iterator;
     
    3637import org.greenstone.util.GlobalProperties;
    3738import org.w3c.dom.Element;
     39import org.w3c.dom.NodeList;
    3840
    3941public class GS2SolrSearch extends SharedSoleneGS2FieldSearch
     
    4547    protected HashMap solr_core_cache;
    4648    protected SolrQueryWrapper solr_src = null;
     49
     50    protected ArrayList<String> _facets = new ArrayList<String>();
    4751
    4852    public GS2SolrSearch()
     
    5761        if (all_solr_cores == null)
    5862        {
    59             // Share one CoreContainer across all sties/collections
     63            // Share one CoreContainer across all sites/collections
    6064            try
    6165            {
    62 
    6366                String gsdl3_home = GlobalProperties.getGSDL3Home();
    6467                String solr_ext_name = GlobalProperties.getProperty("gsdlext.solr.dirname", "solr");
     
    7982    }
    8083
     84    /** configure this service */
     85    public boolean configure(Element info, Element extra_info)
     86    {
     87        if (!super.configure(info, extra_info))
     88        {
     89            return false;
     90        }
     91
     92        Element searchElem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
     93        NodeList configIndexElems = searchElem.getElementsByTagName(GSXML.INDEX_ELEM);
     94
     95        ArrayList<String> chosenFacets = new ArrayList<String>();
     96        for (int i = 0; i < configIndexElems.getLength(); i++)
     97        {
     98            Element current = (Element) configIndexElems.item(i);
     99            if (current.getAttribute(GSXML.FACET_ATT).equals("true"))
     100            {
     101                chosenFacets.add(current.getAttribute(GSXML.NAME_ATT));
     102            }
     103        }
     104       
     105        Element indexListElem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_ELEM + GSXML.LIST_MODIFIER);
     106        NodeList buildIndexElems = indexListElem.getElementsByTagName(GSXML.INDEX_ELEM);
     107
     108        for(int j = 0; j < buildIndexElems.getLength(); j++)
     109        {
     110            Element current = (Element) buildIndexElems.item(j);
     111            for(int i = 0; i < chosenFacets.size(); i++)
     112            {
     113                if (current.getAttribute(GSXML.NAME_ATT).equals(chosenFacets.get(i)))
     114                {
     115                    _facets.add(current.getAttribute(GSXML.SHORTNAME_ATT));
     116                }
     117            }
     118        }
     119       
     120        return true;
     121    }
     122
    81123    public void cleanUp()
    82124    {
     
    91133    protected boolean setUpQueryer(HashMap params)
    92134    {
    93         String indexdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar + "index" + File.separatorChar;
     135        this.solr_src.clearFacets();
     136        this.solr_src.clearFacetQueries();
     137
     138        for (int i = 0; i < _facets.size(); i++)
     139        {
     140            this.solr_src.addFacet(_facets.get(i));
     141        }
    94142
    95143        String index = "didx";
     
    119167            {
    120168                start_page = Integer.parseInt(value);
    121 
    122169            }
    123170            else if (name.equals(MATCH_PARAM))
     
    150197                    index = "didx";
    151198                }
     199            }
     200            else if (name.equals("facets") && value.length() > 0)
     201            {
     202                String[] facets = value.split(",");
     203
     204                for (String facet : facets)
     205                {
     206                    this.solr_src.addFacet(facet);
     207                }
     208            }
     209            else if (name.equals("facetQueries") && value.length() > 0)
     210            {
     211                this.solr_src.addFacetQuery(value);
    152212            }
    153213            else if (name.equals(INDEX_SUBCOLLECTION_PARAM))
     
    190250
    191251        String core_name = site_name + "-" + coll_name + "-" + index;
    192 
     252       
    193253        EmbeddedSolrServer solr_core = null;
    194254
     
    212272    protected Object runQuery(String query)
    213273    {
    214 
    215         /*
    216          * ModifiableSolrParams solrParams = new ModifiableSolrParams();
    217          * solrParams.set("collectionName", myCollection);
    218          * solrParams.set("username", "admin"); solrParams.set("password",
    219          * "password"); solrParams.set("facet", facet); solrParams.set("q",
    220          * query); solrParams.set("start", start); solrParams.set("rows",
    221          * nbDocuments); return server.query(solrParams);
    222          */
    223 
    224         /*
    225          * SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query);
    226          * //solrQuery.set("collectionName", myCollection);
    227          * solrQuery.set("username", "admin"); solrQuery.set("password",
    228          * "password"); solrQuery.set("facet", facet);
    229          * solrQuery.setStart(start); solrQuery.setRows(nbDocuments); //return
    230          * server.query(solrQuery);
    231          */
    232 
    233274        try
    234275        {
     276            //SharedSoleneQueryResult sqr = this.solr_src.runQuery(query);
    235277            SharedSoleneQueryResult sqr = this.solr_src.runQuery(query);
     278
    236279            return sqr;
    237280        }
Note: See TracChangeset for help on using the changeset viewer.