Forum

Thread tagged as: Problem, Add-on-development, Runway

Searching Collections in CMS

Hi,

I have a collection in a Perch Runway site that has over 500 items. The items are added via an add on using POST data from a 3rd party API.

Once in the CMS I cannot seem to search on these collections items if they are added via the add on, if I add an item manually it is searchable. I have added the part of the code below that published the collection item.

public function create(array $arr){
        //set collection item vars
        $itemID = (string) $this->collectionItems->get_next_id();
        //set collection item id
        $arr['_id'] = $itemID;
        //set the search strig
        $this->setSearch($arr);
        //set details with collection id
        $details = array('collectionID' => $this->collectionID);

        //instantiate collection
        $collection = new PerchContent_Collection($details);

        //add a new collection item
        $newItem = $collection->add_new_item();

        if (!$newItem) {
            // err
            $this->hasError = true;
        }
        //store the item in an accessible var
        $item = $collection->get_items_for_editing($itemID);

        //add item row to the details var
        $details['itemRowID'] = $item[0]['itemRowID'];

        //instantiate collection item, passing the details
        $collectionItem = new PerchContent_CollectionItem($details);

        //update this collection item
        $collectionItem->update(array(
            'itemJSON' => PerchUtil::json_safe_encode($arr),
            'itemSearch' => strip_tags($this->itemSearch),
            'itemUpdatedBy' => 1,
        ));

        //publish the item
        $collectionItem->publish();

        //index the item
        $collectionItem->index();
        // return true if hasError is false = no errors
        return !$this->hasError;
    }
Lee Goodman

Lee Goodman 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is itemSearchable set to 1 ?

Thanks Drew, where would I check this.

We have added this function in the add on

public function setSearch($arr){
        //set search string
        $this->itemSearch = $arr['title']." ".$arr['reference']." ".$arr['jobDesc'];
    }

Which adds the relevant search searchable content into the "itemSearch" column in "collection_items" , we weren't doing this previously.

I haven't had a chance to test yet as I have another more urgent issue with the site, I have raised this as a separate issue on the forum.

Thanks

Lee

Drew McLellan

Drew McLellan 2638 points
Perch Support

You would check in the database.

Thanks Drew, found it. "collectionSearchable" is set to 1 for all our collections.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. You might want to turn debug on, take a look at the search query, run it against your db and see if you can debug it.