Skip to content

Commit

Permalink
[Fixes #41918505] Name attribute is now displayed correctly if used a…
Browse files Browse the repository at this point in the history
…s facet. Attribute order initialization now takes the ratio between items and facet values into account when determining which attributes should be shown as facets by default.
  • Loading branch information
ngehlenborg committed Jan 24, 2013
1 parent e7ac1e8 commit 5352fdd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
44 changes: 39 additions & 5 deletions refinery/data_set_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,50 @@ class AnnotatedNode(models.Model):


def _is_internal_attribute(attribute):
return attribute in [ "uuid", "study_uuid", "assay_uuid", "file_uuid", "type", "is_annotation", "species", "genome_build" ]
return attribute in [ "uuid", "study_uuid", "assay_uuid", "file_uuid", "type", "is_annotation", "species", "genome_build", "name" ]

def _is_active_attribute(attribute):
return (not _is_internal_attribute(attribute) and attribute not in ["name"] )
return (not _is_internal_attribute(attribute) and attribute not in [] )

def _is_ignored_attribute(attribute):
"""
Ignore Django internal Solr fields.
"""
return attribute in [ "django_ct", "django_id", "id" ]
return attribute in [ "django_ct", "django_id", "id" ]

def _is_facet_attribute(attribute,study,assay):
"""
Tests if a an attribute should be used as a facet by default.
:param attribute: The name of the attribute.
:type attribute: string
:returns: True if the ratio between items in the data set and the number of facet attribute values is smaller than settings.DEFAULT_FACET_ATTRIBUTE_VALUES_RATIO, false otherwise.
"""
ratio = 0.5

query = settings.REFINERY_SOLR_BASE_URL + "data_set_manager" + "/select?" + "q=django_ct:data_set_manager.node&wt=json&start=0&rows=1&fq=(study_uuid:" + study.uuid + "%20AND%20assay_uuid:" + assay.uuid + "%20AND%20is_annotation:false%20AND%20(type:%22Array%20Data%20File%22%20OR%20type:%22Derived%20Array%20Data%20File%22%20OR%20type:%22Raw%20Data%20File%22%20OR%20type:%20%22Derived%20Data%20File%22))&facet=true&facet.field=" + attribute + "&facet.sort=count&facet.limit=-1"

logger.debug( "Query for initialize_attribute_order: %s" % ( query, ) )

# proper url encoding
query = urllib2.quote(query, safe="%/:=&?~#+!$,;'@()*[]")

# opening solr query results
results = urllib2.urlopen( query ).read()

logger.debug( "Query results for initialize_attribute_order: %s" % ( results, ) )

# converting results into json for python
results = simplejson.loads(results)


items = results["response"]["numFound"]
attributeValues = len( results["facet_counts"]["facet_fields"][attribute] )/2

logger.debug( results["facet_counts"]["facet_fields"] );

return ( attributeValues/items ) < ratio


def initialize_attribute_order( study, assay ):
Expand All @@ -504,7 +538,7 @@ def initialize_attribute_order( study, assay ):
:returns: Number of attributes that were indexed.
"""

query = settings.REFINERY_SOLR_BASE_URL + "data_set_manager" + "/select?" + "q=django_ct:data_set_manager.node&wt=json&start=0&rows=1&fq=(study_uuid:" + study.uuid + "%20AND%20assay_uuid:" + assay.uuid + "%20AND%20is_annotation:false%20AND%20(type:%22Array%20Data%20File%22%20OR%20type:%22Derived%20Array%20Data%20File%22%20OR%20type:%22Raw%20Data%20File%22%20OR%20type:%20%22Derived%20Data%20File%22))&facet.sort=count&facet.limit=-1"
query = settings.REFINERY_SOLR_BASE_URL + "data_set_manager" + "/select?" + "q=django_ct:data_set_manager.node&wt=json&start=0&rows=1&fq=(study_uuid:" + study.uuid + "%20AND%20assay_uuid:" + assay.uuid + "%20AND%20is_annotation:false%20AND%20(type:%22Array%20Data%20File%22%20OR%20type:%22Derived%20Array%20Data%20File%22%20OR%20type:%22Raw%20Data%20File%22%20OR%20type:%20%22Derived%20Data%20File%22))&facet=true&facet.sort=count&facet.limit=-1"

logger.debug( "Query for initialize_attribute_order: %s" % ( query, ) )

Expand All @@ -523,7 +557,7 @@ def initialize_attribute_order( study, assay ):
rank = 0
for key in results["response"]["docs"][0]:

is_facet = True
is_facet = _is_facet_attribute(key,study,assay)
is_exposed = True
is_internal = _is_internal_attribute(key);
is_active = _is_active_attribute(key)
Expand Down
7 changes: 5 additions & 2 deletions refinery/data_set_manager/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def index_queryset(self):
def prepare(self, object):
data = super(NodeIndex, self).prepare(object)
annotations = AnnotatedNode.objects.filter( node=object )

uuid = str( object.study.id )

if object.assay is not None:
Expand Down Expand Up @@ -81,7 +81,10 @@ def prepare(self, object):

# add type as dynamic field to get proper facet values
data["REFINERY_TYPE_" + uuid + "_s"] = object.type


# add type as dynamic field to get proper facet values
data["REFINERY_NAME_" + uuid + "_s"] = object.name

# add file type as facet value
file_store_item = file_store_tasks.read( object.file_uuid );

Expand Down
4 changes: 2 additions & 2 deletions refinery/static/js/refinery/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ $(document).ready(function() {
var showAnnotation = false;

var ignoredFieldNames = [ "django_ct", "django_id", "id" ];
var hiddenFieldNames = [ "uuid", "study_uuid", "assay_uuid", "type", "is_annotation", "species", "genome_build" ]; // TODO: make these regexes
var invisibleFieldNames = [ "name" ];
var hiddenFieldNames = [ "uuid", "study_uuid", "assay_uuid", "type", "is_annotation", "species", "genome_build", "name" ]; // TODO: make these regexes
var invisibleFieldNames = [];


var facets = {};
Expand Down
9 changes: 9 additions & 0 deletions refinery/static/js/refinery/solr/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function prettifySolrFieldName( name, isTitle )
name = "Material Type";
}

var position = name.indexOf( "Label_" );
if ( position != -1 ) {
name = "Label";
}

var position = name.indexOf( "REFINERY_TYPE_" );
if ( position == 0 ) {
name = "Type";
Expand All @@ -38,6 +43,10 @@ function prettifySolrFieldName( name, isTitle )
name = "File Type";
}

var position = name.indexOf( "REFINERY_NAME_" );
if ( position == 0 ) {
name = "Name";
}

name = name.replace( /\_/g, " " );

Expand Down

0 comments on commit 5352fdd

Please sign in to comment.