Commits

Anonymous committed d5bd830

add notion of implicit facets

Comments (0)

Files changed (9)

     # default minimum number of results required to trigger a facet being included (integer)
     "facet_mincount" : 1,
     
+    "text_search_field" : "*",
+    
     "always_visible" : 5,
     
     # The fields which are plain text/value facets, and their display names
 from datetime import datetime, timedelta
 
 class SolrEyesController(object):
-    def GET(self):
+    def GET(self, path=None):
         # get the args (if available) out of the request
         a = web.input().get("a")
         args = None
             args = config.get_default_args()
             initial_request = True
         
+        # fold in the free text search options if relevant
+        if web.input().get("q") is not None:
+            if web.input().get("q") != "":
+                args["q"][config.text_search_field] = [web.input().get("q")]#.split(' ')
+            else:
+                if config.text_search_field in args["q"].keys():
+                    del args["q"][config.text_search_field]
+        
+        implicit_facets = {}
+        if path is not None:
+            # split the path by the middle "/"
+            path = path.strip()
+            if path.endswith("/"):
+                path = path[:-1]
+            bits = path.split('/')
+            if len(bits) % 2 == 0:
+                initial_request = False
+                config.base_url = config.base_url + path
+                if not args.has_key('q'):
+                    args['q'] = {}
+                for i in range(0, len(bits), 2):
+                    field = bits[i]
+                    value = bits[i+1]
+                    if args['q'].has_key(field):
+                        args['q'][field].append(value)
+                    else:
+                        args['q'][field] = [value]
+                    if implicit_facets.has_key(field):
+                        implicit_facets[field].append(value)
+                    else:
+                        implicit_facets[field] = [value]
+        
+        # set the implicit facets for the UI to use
+        properties['implicit_facets'] = implicit_facets
+        
         # set the UrlManager for the UI to use
-        properties['url_manager'] = UrlManager(config, args)
+        properties['url_manager'] = UrlManager(config, args, implicit_facets)
         
         # create a solr connection and get the results back
         s = Solr(config)
         return sorted(tups, key=operator.itemgetter(0))
         
 class UrlManager(object):
-    def __init__(self, config, args):
+    def __init__(self, config, args, implicit_facets):
         self.config = config
         self.args = args if args is not None else self.config.get_default_args()
+        self.implicit_facets = implicit_facets
+        self.base_args = self.strip_implicit_facets()
+    
+    def strip_implicit_facets(self):
+        myargs = deepcopy(self.args)
+        if self.implicit_facets is None:
+            return myargs
+        if not self.args.has_key('q'):
+            return myargs
+        
+        for field in self.implicit_facets.keys():
+            if myargs['q'].has_key(field):
+                del myargs['q'][field]
+        return myargs
     
     def get_add_url(self, field, value, upper=None):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         if myargs["q"].has_key(field):
             if upper is None and value not in myargs["q"][field]:
                 myargs["q"][field].append(value)
         return self.config.base_url + "?a=" + urllib2.quote(j)
         
     def get_add_date_url(self, field, value, upper=None):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         value = '{0.year}-{0.month:{1}}-{0.day:{1}}T{0.hour:{1}}:{0.minute:{1}}:{0.second:{1}}Z'.format(value, '02')
         if upper is not None and upper != -1:
             upper = '{0.year}-{0.month:{1}}-{0.day:{1}}T{0.hour:{1}}:{0.minute:{1}}:{0.second:{1}}Z'.format(upper, '02')
         return self.config.base_url + "?a=" + urllib2.quote(j)
 
     def get_delete_url(self, field, value=None):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         if value is not None:
             myargs['q'][field].remove(value)
             if len(myargs['q'][field]) == 0:
         return self.config.base_url + "?a=" + urllib2.quote(j)
         
     def get_position_url(self, position):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         myargs["start"] = position
         j = json.dumps(myargs)
         return self.config.base_url + "?a=" + urllib2.quote(j)
         
     def get_rpp_url(self, rpp):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         myargs["rows"] = int(rpp)
         j = json.dumps(myargs)
         return self.config.base_url + "?a=" + urllib2.quote(j)
         
     def get_sort_url(self, field, direction):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         if myargs.has_key("sort"):
             isnew = True
             for i in range(len(myargs['sort'])):
         return self.config.base_url + "?a=" + urllib2.quote(j)
         
     def get_unsort_url(self, field):
-        myargs = deepcopy(self.args)
+        myargs = deepcopy(self.base_args)
         for i in range(len(myargs['sort'])):
             f, direction = myargs['sort'][i]
             if f == field:
         
     def initial(self, args):
         args = deepcopy(args)
-        args["q"]["*"] = "*"
+        if self.config.text_search_field not in args["q"].keys():
+            args["q"]["*"] = "*"
         args["rows"] = 0
         return self._do_query(args)
         
                     qs.append(field + ":" + value)
         q = " AND ".join(qs)
         
+        if q == "": 
+            q = "*:*"
+        
         # start position (for paging)
         if args.has_key("start"):
             solr_args["start"] = args["start"]
         
+        # FIXME: add null checks
+        
         # set up the ranged search parameters
         for f in args["facet_range"].keys():
             if solr_args.has_key("facet.range"):
 from solreyes import SolrEyesController
 
 urls = (
-	'/.*', 'SolrEyesController'
+	'/(.*)', 'SolrEyesController',
 )
 
 app = web.application(urls, globals())

static/styless.css

     border-right: 1px solid #000000;
     padding-left: 3px;
     padding-right: 3px;
+}
+
+.implicit_title {
+    width: 100%;
+    clear: both;
+    text-align: center;
+}
+
+.implicit_title h1 {
+    font-weight: bold;
+    text-align: center;
+    font-size: 140%;
 }

templates/facet-extra.mako

 % for facet in c['config'].display_facet_order:
-    <div class="facet">
-    % if c['results'].has_values(facet):
-        <div class="facet_heading">
-            <a href="" id="fh_${facet}">+&nbsp;${c['config'].get_facet_display(facet)}</a>
-        </div>
-        <div id="selected_${facet}" class="facet_value">
+    % if facet not in c['implicit_facets']:
+        <div class="facet">
+        % if c['results'].has_values(facet):
+            <div class="facet_heading">
+                <a href="" id="fh_${facet}">+&nbsp;${c['config'].get_facet_display(facet)}</a>
+            </div>
+            <div id="selected_${facet}" class="facet_value">
+            
+            % if facet in c['config'].facet_ranges.keys():
+            
+                % if c['results'].in_args(facet):
+                    % if c['results'].get_selected_range_end(facet) != -1:
+                        <em>${c['results'].get_selected_range_start(facet)} - ${c['results'].get_selected_range_end(facet)}
+                        (${c['results'].numFound()})
+                        </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
+                    % else:
+                        <em>${c['results'].get_selected_range_start(facet)}+
+                        (${c['results'].numFound()})
+                        </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
+                    % endif
+                % endif
+                
+            % elif facet in c['config'].facet_dates.keys():
+                % if c['results'].in_args(facet):
+                    % if c['results'].get_selected_range_end(facet) != -1:
+                        <em>
+                        ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}
+                        % if c['config'].display_upper(facet, str(c['results'].get_selected_range_start(facet)), str(c['results'].get_selected_range_end(facet))):
+                            - 
+                            ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_end(facet)))}
+                        % endif
+                        (${c['results'].numFound()})
+                        </em>
+                        &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
+                    % else:
+                        <em>${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}+
+                        (${c['results'].numFound()})
+                        </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
+                    % endif
+                % endif 
         
-        % if facet in c['config'].facet_ranges.keys():
-        
-            % if c['results'].in_args(facet):
-                % if c['results'].get_selected_range_end(facet) != -1:
-                    <em>${c['results'].get_selected_range_start(facet)} - ${c['results'].get_selected_range_end(facet)}
-                    (${c['results'].numFound()})
-                    </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
-                % else:
-                    <em>${c['results'].get_selected_range_start(facet)}+
-                    (${c['results'].numFound()})
-                    </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
+            % else:
+            
+                % for value, count in c['results'].get_ordered_facets(facet):
+                    % if c['results'].in_args(facet, value):
+                        <em>
+                        ${c['config'].get_value_display(facet, value)} (${count})
+                        </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet, value)}">x</a>
+                        <br/>
+                    % endif
+                % endfor
+                
+            % endif
+            </div>
+            
+            <div id="fr_${facet}" style="display:none" class="facet_value">
+            % if facet in c['config'].facet_ranges.keys():
+                % if not c['results'].in_args(facet):
+                    % for lower, upper, count in c['results'].get_ordered_facets(facet):
+                        <a href="${c['url_manager'].get_add_url(facet, lower, upper)}">
+                        % if upper != -1:
+                            ${lower} - ${upper} (${count})
+                        % else:
+                            ${lower}+ (${count})
+                        % endif
+                        </a><br/>
+                    % endfor
                 % endif
+            % elif facet in c['config'].facet_dates.keys():
+                % if not c['results'].in_args(facet):
+                    % for lower, upper, count in c['results'].get_ordered_facets(facet):
+                        <a href="${c['url_manager'].get_add_date_url(facet, lower, upper)}">
+                        % if upper != -1:
+                            ${c['config'].get_value_display(facet, str(lower))}
+                            % if c['config'].display_upper(facet, str(lower), str(upper)):
+                                - 
+                                ${c['config'].get_value_display(facet, str(upper))} 
+                            % endif
+                            (${count})
+                        % else:
+                            ${c['config'].get_value_display(facet, str(lower))}+ (${count})
+                        % endif
+                        </a><br/>
+                    % endfor
+                % endif
+            % else:
+                % for value, count in c['results'].get_ordered_facets(facet):
+                    % if not c['results'].in_args(facet, value):
+                        <a href="${c['url_manager'].get_add_url(facet, value)}">
+                        ${c['config'].get_value_display(facet, value)} (${count})
+                        </a><br/>
+                    % endif
+                % endfor
             % endif
-            
-        % elif facet in c['config'].facet_dates.keys():
-            % if c['results'].in_args(facet):
-                % if c['results'].get_selected_range_end(facet) != -1:
-                    <em>
-                    ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}
-                    % if c['config'].display_upper(facet, str(c['results'].get_selected_range_start(facet)), str(c['results'].get_selected_range_end(facet))):
-                        - 
-                        ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_end(facet)))}
-                    % endif
-                    (${c['results'].numFound()})
-                    </em>
-                    &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
-                % else:
-                    <em>${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}+
-                    (${c['results'].numFound()})
-                    </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a><br/>
-                % endif
-            % endif 
-    
+            </div>
+                
         % else:
-        
-            % for value, count in c['results'].get_ordered_facets(facet):
-                % if c['results'].in_args(facet, value):
-                    <em>
-                    ${c['config'].get_value_display(facet, value)} (${count})
-                    </em>&nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet, value)}">x</a>
-                    <br/>
-                % endif
-            % endfor
-            
+            <div class="empty_facet">
+                <strong>${c['config'].get_facet_display(facet)}</strong>
+            </div>
         % endif
         </div>
-        
-        <div id="fr_${facet}" style="display:none" class="facet_value">
-        % if facet in c['config'].facet_ranges.keys():
-            % if not c['results'].in_args(facet):
-                % for lower, upper, count in c['results'].get_ordered_facets(facet):
-                    <a href="${c['url_manager'].get_add_url(facet, lower, upper)}">
-                    % if upper != -1:
-                        ${lower} - ${upper} (${count})
-                    % else:
-                        ${lower}+ (${count})
-                    % endif
-                    </a><br/>
-                % endfor
-            % endif
-        % elif facet in c['config'].facet_dates.keys():
-            % if not c['results'].in_args(facet):
-                % for lower, upper, count in c['results'].get_ordered_facets(facet):
-                    <a href="${c['url_manager'].get_add_date_url(facet, lower, upper)}">
-                    % if upper != -1:
-                        ${c['config'].get_value_display(facet, str(lower))}
-                        % if c['config'].display_upper(facet, str(lower), str(upper)):
-                            - 
-                            ${c['config'].get_value_display(facet, str(upper))} 
-                        % endif
-                        (${count})
-                    % else:
-                        ${c['config'].get_value_display(facet, str(lower))}+ (${count})
-                    % endif
-                    </a><br/>
-                % endfor
-            % endif
-        % else:
-            % for value, count in c['results'].get_ordered_facets(facet):
-                % if not c['results'].in_args(facet, value):
-                    <a href="${c['url_manager'].get_add_url(facet, value)}">
-                    ${c['config'].get_value_display(facet, value)} (${count})
-                    </a><br/>
-                % endif
-            % endfor
-        % endif
-        </div>
-            
-    % else:
-        <div class="empty_facet">
-            <strong>${c['config'].get_facet_display(facet)}</strong>
-        </div>
     % endif
-    </div>
 % endfor

templates/header.mako

 <div id="header">
 
-    <a href="/"><img id="logo" src="/static/brunel.png" alt="Brunel University"/></a>
+    <a href="${c['config'].base_url}"><img id="logo" src="/static/brunel.png" alt="Brunel University"/></a>
     <div id="title">
         ${c['config'].service_name}
     </div>

templates/implicit-title.mako

+<div class="implicit_title">
+    % for field in c['implicit_facets'].keys():
+        <h1>${c['config'].get_facet_display(field)} : ${", ".join(c['implicit_facets'][field])}</h1>
+    % endfor
+</div>

templates/search-summary.mako

 <div class="search_constraints">
 % for facet, values in c['results'].get_search_constraints().iteritems():
    
-    % if facet in c['config'].facet_ranges.keys():
-        <div class="search_constraint">
-            ${c['config'].get_facet_display(facet)} : 
-    
-            % if c['results'].get_selected_range_end(facet) != -1:
-                ${c['results'].get_selected_range_start(facet)} - ${c['results'].get_selected_range_end(facet)}
-            % else:
-                <em>${c['results'].get_selected_range_start(facet)}+
-            % endif
-            &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a>
-        </div>
-            
-    % elif facet in c['config'].facet_dates.keys():
-        <div class="search_constraint">
-            ${c['config'].get_facet_display(facet)} : 
-            % if c['results'].get_selected_range_end(facet) != -1:
-                ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}
-                % if c['config'].display_upper(facet, str(c['results'].get_selected_range_start(facet)), str(c['results'].get_selected_range_end(facet))):
-                    - 
-                    ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_end(facet)))}
-                % endif
-            % else:
-                ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}+
-            % endif
-            &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a>
-        </div>
-
-    % else:
-        % for value in values:
+   % if facet not in c['implicit_facets']:
+   
+        % if facet in c['config'].facet_ranges.keys():
             <div class="search_constraint">
                 ${c['config'].get_facet_display(facet)} : 
-                ${c['config'].get_value_display(facet, value)}
-                &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet, value)}">x</a>
+        
+                % if c['results'].get_selected_range_end(facet) != -1:
+                    ${c['results'].get_selected_range_start(facet)} - ${c['results'].get_selected_range_end(facet)}
+                % else:
+                    <em>${c['results'].get_selected_range_start(facet)}+
+                % endif
+                &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a>
             </div>
-        % endfor
+                
+        % elif facet in c['config'].facet_dates.keys():
+            <div class="search_constraint">
+                ${c['config'].get_facet_display(facet)} : 
+                % if c['results'].get_selected_range_end(facet) != -1:
+                    ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}
+                    % if c['config'].display_upper(facet, str(c['results'].get_selected_range_start(facet)), str(c['results'].get_selected_range_end(facet))):
+                        - 
+                        ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_end(facet)))}
+                    % endif
+                % else:
+                    ${c['config'].get_value_display(facet, str(c['results'].get_selected_range_start(facet)))}+
+                % endif
+                &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet)}">x</a>
+            </div>
+    
+        % else:
+            % for value in values:
+                <div class="search_constraint">
+                    ${c['config'].get_facet_display(facet)} : 
+                    ${c['config'].get_value_display(facet, value)}
+                    &nbsp;<a class="delete_url" href="${c['url_manager'].get_delete_url(facet, value)}">x</a>
+                </div>
+            % endfor
+        % endif
+    
     % endif
 % endfor
 </div>

templates/solreyes.mako

         % if c['results'].set_size() == 0:
             <%include file="/noresults.mako"/>
         % else:
+            <%include file="/implicit-title.mako"/>
             <%include file="/search-summary.mako"/>
             <%include file="/sort-options.mako"/>
             <%include file="/paging.mako"/>