Custom Asset with boolean attribute - Searching not working?


(Baylward) #1

Hi,


I've build a custom asset and added a number of attributes to it, including some boolean attributes. I've created a search page with a single search field for the boolean attribute. The search page outputs a drop-down box for True and False. If I select True I get no results (even for the assets with the value set.) If I select False I get all assets (whether the attribute is true or false).



I've got a similar problem for a selection attribute. The search form displays a drop-down with all the selection options, but when I select any of them I get no results.



Has anybody come across this before?



Thanks,

Bruce


(Baylward) #2

It seems that the False case is treated as an empty search. If I actually set the search page to not allow empty searches then I get no results for the False case as well.


(Baylward) #3

Looking at the source code and the search SQL select statement:


SELECT a.assetid, SUM(ai.score) as search_score FROM sq_ast a INNER JOIN sq_ast_lnk l ON l.minorid = a.assetid INNER JOIN sq_ast_lnk_tree t ON t.linkid = l.linkid INNER JOIN sq_ast_perm p ON p.assetid = a.assetid LEFT JOIN sq_vw_ast_role r ON p.userid = r.roleid INNER JOIN sq_sch_idx ai ON ai.assetid = a.assetid WHERE ((t.treeid LIKE ‘000700030005%’)) AND (p.userid IN (‘7020’,‘7’,‘7’) OR r.userid IN (‘7020’,‘7’,‘7’)) AND (( (p.permission = ‘1’ AND ( p.userid <> ‘7’ OR r.userid <> ‘7’ OR (p.userid = ‘7’ AND granted = 1) OR (r.userid = ‘7’ AND granted = 1) ) ) OR (p.permission > ‘1’ AND p.granted = 1) )) AND (a.status IN (‘16’, ‘32’, ‘64’, ‘128’, ‘256’)) AND (a.type_code IN ( SELECT type_code FROM sq_ast_typ_inhd WHERE type_code IN (‘organisation_sp’) )) AND (ai.component = ‘attr:youth’) AND [color="#ff0000"](ai.value LIKE ‘’) GROUP BY a.assetid HAVING MIN(p.granted) <> 0



It seems to me that the search_manager is executing a WordSearch, even though this is a boolean attribute, and searching for an empty value. Does the search_manager support boolean attributes?



Also, looking at search_manager.inc in the _processNumericSearch() function on line 2116 it calls the search plugin’s processDateSearch() function. This does not look right to me.


(Baylward) #4

The same seems to happening with selection attributes. Here is the SQL:


SELECT a.assetid, SUM(ai.score) as search_score FROM sq_ast a INNER JOIN sq_ast_lnk l ON l.minorid = a.assetid INNER JOIN sq_ast_lnk_tree t ON t.linkid = l.linkid INNER JOIN sq_ast_perm p ON p.assetid = a.assetid LEFT JOIN sq_vw_ast_role r ON p.userid = r.roleid INNER JOIN sq_sch_idx ai ON ai.assetid = a.assetid WHERE ((t.treeid LIKE ‘000700030005%’)) AND (p.userid IN (‘7020’,‘7’,‘7’) OR r.userid IN (‘7020’,‘7’,‘7’)) AND (( (p.permission = ‘1’ AND ( p.userid <> ‘7’ OR r.userid <> ‘7’ OR (p.userid = ‘7’ AND granted = 1) OR (r.userid = ‘7’ AND granted = 1) ) ) OR (p.permission > ‘1’ AND p.granted = 1) )) AND (a.status IN (‘16’, ‘32’, ‘64’, ‘128’, ‘256’)) AND (a.type_code IN ( SELECT type_code FROM sq_ast_typ_inhd WHERE type_code IN (‘organisation_sp’) )) AND (ai.component = ‘attr:focus’) AND [color="#FF0000"](ai.value LIKE ‘’) GROUP BY a.assetid HAVING MIN(p.granted) <> 0


(Avi Miller) #5

What does your custom asset's management class look like? Also, can you check the sq_sch_idx table to see if your attributes are being indexed at all?


(Baylward) #6

It looks like these are the only components indexed:


created



name



attr:name



short_name



attr:short_name



published



status_changed



updated



So it looks like none of my custom attributes are indexed.


(Baylward) #7

Here is the management class:


[codebox]<?php

require_once SQ_INCLUDE_PATH.'/asset_management.inc';

class Organisation_SP_Management extends Asset_Management {



function Organisation_SP_Management(&$pm)

{

$this->Asset_Management($pm);

$this->vars = Array (

// Application details

'type' => array('added' => '0.1',

'type' => 'selection',

'default' => 'Organisation',

'parameters' => Array(

'multiple' => FALSE,

'allow_empty' => FALSE,

'options' => Array(

'Organisation' => 'Organisation',

'Individual' => 'Individual'

)

)

),

'referral' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),



// Organisation

'age_groups' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),

'contact_hours' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),

'service_type' => Array(

'added' => '0.1',

'type' => 'selection',

'default' => 'Health Service',

'parameters' => Array(

'multiple' => FALSE,

'allow_empty' => FALSE,

'options' => Array(

'Health Service' => 'Health Service',

'Social Service' => 'Social Service',

'Both' => 'Both'

)

)

),

'languages' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),

'cost' => Array(

'added' => '0.1',

'type' => 'selection',

'default' => 'No cost',

'parameters' => Array(

'multiple' => FALSE,

'allow_empty' => FALSE,

'options' => Array(

'No cost' => 'No cost',

'Koha / Donation' => 'Koha / Donation',

'Sliding Scale' => 'Sliding Scale',

'Less than $30' => 'Less than $30',

'From $31 to $70' => 'From $31 to $70'

,

'$71 or more' => '$71 or more'

)

)

),

'negotiable' => Array(

'added' => '0.1',

'type' => 'boolean',

'default' => FALSE

),

'accredited' => Array(

'added' => '0.1',

'type' => 'boolean',

'default' => FALSE

),

'accredited_by' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),

'email' => Array(

'added' => '0.1',

'type' => 'email',

'default' => ''

),

'website' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),



// Service details

'services' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),

'focus' => Array(

'added' => '0.1',

'type' => 'selection',

'default' => 'Mainstream Service Provider',

'parameters' => Array(

'multiple' => FALSE,

'allow_empty' => FALSE,

'options' => Array(

'Asian Service Provider' => 'Asian Service Provider',

'Kaupapa Maori Service Provider' => 'Kaupapa Maori Service Provider',

'Mainstream Service Provider' => 'Mainstream Service Provider',

'New Settlers Service Provider' => 'New Settlers Service Provider',

'Pacific Peoples Service Providers' => 'Pacific Peoples Service Providers',

'Counties Manukau Mental Health Mobile Community Support' => 'Counties Manukau Mental Health Mobile Community Support'

)

)

),

'older_persons' => Array(

'added' => '0.1',

'type' => 'boolean',

'default' => FALSE

),

'palliative_care' => Array(

'added' => '0.1',

'type' => 'boolean',

'default' => FALSE

),

'well_child' => Array(

'added' => '0.1',

'type' => 'boolean',

'default' => FALSE

),

'youth' => Array(

'added' => '0.1',

'type' => 'boolean',

'default' => FALSE

),

'groups' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

),



// Profile

'profile' => Array(

'added' => '0.1',

'type' => 'wysiwyg',

'default' => ''

),



// Subscribe

'subscribe' => Array(

'added' => '0.1',

'type' => 'selection',

'default' => 'YES!',

'parameters' => Array(

'multiple' => FALSE,

'allow_empty' => FALSE,

'options' => Array(

'YES!' => 'YES!',

'No thanks' => 'No thanks'

)

)

),



// Notes

'notes' => Array(

'added' => '0.1',

'type' => 'text',

'default' => ''

)

);

}//end constructor





}//end class



?>[/codebox]


(Greg Sherwood) #8

It could be the minimal word length setting in Search Manager, not indexing 1 and 0 because they are too short. We normally replace boolean attributes with selection attributes where the keys are "true" and "false" (or whatever you want them to be) so that searching has something to find.


(Avi Miller) #9

Greg, don't you need the is_admin => 'false' setting on the attributes to get indexed?


(Greg Sherwood) #10

I thought that was FALSE by default, but it wouldn't surprise me if I was wrong about that. Setting the value is a good idea.


(Avi Miller) #11

I'm pretty sure I had to set it specifically. It could be why none of the attributes are being indexed at all, particularly the ones longer than the minimum word length.

(Baylward) #12

I've added is_admin => 'false' to the attributes and it now adds these attributes once updated. Thanks for the help.


(Baylward) #13

For the boolean attributes, when I search with True it finds the correct items. When I search with false it is still treated as an empty search.