Suggest search

About

Returns a component that handles suggest searches towards Open Content and builds up a query that will return a set of requested items

Can also be configured to handle date searches:

Handles created date sorting by default but through config can add multiple sorting fields

How to use

import { Component } from 'react'
import { usePortal, getMappedId } from 'Dashboard'
import SSConfigFunc from './SuggestSearchConfig'


class MyClass extends Component {
    constructor(props) {
        super(props)
        
        this.autoSearch = true
        this.ocInstance = {} //instance of Content Agent oc instance
        this.suggestSearch = null
        
        this.state = {
            isSearching: false,
            start: 0,
            limit: 15
        }
    }

    componentDidMount() {
        this.suggestSearch = usePortal(getMappedId('@plugin_bundle', 'portal', 'MY_SS_PORTAL_ID'))
    }
    
    render() {
        const {localize} = this.props
        const {start, limit} this.state
        const SuggestSearch = this.suggestSearch
        const suggestSearchConfig = SSConfigFunc({
            start: start,
            limit: limit
        })
        
        return (
            {SuggestSearch &&
                <SuggestSearch
                    dateSearch
                    cacheLastSearch
                    cacheKey={this.props.id}
                    onSearch={this.onSearch}
                    ocInstance={this.ocInstance}
                    autoSearch={this.autoSearch}
                    suggestSearchConfig={suggestSearchConfig}
                    className={"@plugin_bundle_class-suggest-search"}
                    searching={isSearching => this.setState({ isSearching })}
                    localizations={{
                        searchAgain: localize.searchAgain,
                        saveSearch: localize.saveSearch,
                        savedSearches: localize.savedSearches,
                        from: localize.from,
                        to: localize.to,
                        placeholder: localize.placeholder,
                        updated: localize.updated,
                        created: localize.created
                    }}
                />
            }
        )
    }
}
const suggestSearchConfig = {
    suggestFields: [
        {
            name: 'PubStatus', 
            order: 10
        }, 
        {
            name: 'Tags', 
            order: 15 
        },
        {
            name: 'Authors',
            order: 20
        }
    ],
    suggestLabels: {
        'PubStatus': 'Status', 
        'Tags': 'Tagg', 
        'Authors': 'Författare'
    },
    searchOptions: {
        start: 0,
        limit: 15,
        property: [
            'uuid', 
            'PubStatus', 
            'Tag', 
            'Authors',
            'ConceptRelations.headline'
        ],
        filters: [
            {
                property: 'ConceptRelations',
                q: 'ConceptStatus: usable',
                start: 0,
                limit: 1
            }
        ],
        defaultQuery: '*:* NOT PubStatus:draft',
        filterQuery: 'contenttype:Article',
        sortField: 'updated',
        sortAscending: false
    },
    dateOptions: { // requires dateSearch true as a property
        properties: [
            {
                sortable: true,
                label: 'Publish date',
                value: 'WriterPubStart'
            }
        ],
    },
    freeTextOrder: 0
}

Last updated