safwansamsudeen / frappe_search

MIT License
6 stars 2 forks source link

Frappe Search

How To Use

To your app's hooks.py, add the following variable. It should be a dictionary of dictionaries with the key being the DocType name, and the dictionary containing the content fields("mandatory"), the "title" field (optional, defaults to name), and the "extras" fields (optional, defaults to []).

frappe_search_doctypes = {
    "GP Discussion": {
        "content": ["content"],
        "extras": ["team", "project"],
        "title": "title",
    }
}

What is the difference between content and extras? Content and title fields will be used when searching. Extras are fields which will be returned to you as part of the search result, but will not be used in the searching.

To build the index: go over to the Search page and click on "Index". Alternatively, run the following command:

bench --site gameplan.test execute frappe_search.core.build_index

To search: by default, the app provides a search interface to test at the Search page. You can call frappe_search.core.search passing in query to get search results, though.

frappe.call({
    method: 'frappe_search.core.search', 
    args: {query: 'toykraft'}, 
    callback: (e) => {
        console.log(e.message)
    }
})
// Output
{
    "results": [
        ...
    ],
    "duration": 16.167,
    "total": 3
}

Each record will be have the following keys:

Configuration

search accepts the following two optional arguments:

build_index can have take in the following optional argument:

License

mit