-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸 Add support for search engine customisation
- Loading branch information
Showing
6 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Search | ||
|
||
### How-to | ||
|
||
1. Create a JSON file somewhere | ||
2. This JSON file need to follow the same structure of [Fuse.js](https://fusejs.io/). | ||
3. Open the workflow, and go to the workflow configuration window (the icon like this [x]) | ||
4. Add new environment variable: | ||
- name: `jb_search_customisation_file` | ||
- value: the path to your JSON file (relative to your home - ex: `/.config/alfred-jetbrains/search.json`) | ||
|
||
Example: | ||
|
||
```json | ||
{ | ||
"keys": [ | ||
{ "name": "title", "weight": 1 }, | ||
{ "name": "subtitle", "weight": 0.1 } | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const alfy = require("alfy"); | ||
const fs = require("fs"); | ||
|
||
const searchOptions = () => { | ||
let fuseOptions = { | ||
shouldSort: true, | ||
threshold: 0.4, | ||
location: 0, | ||
distance: 80, | ||
maxPatternLength: 32, | ||
minMatchCharLength: 2, | ||
keys: [{ name: "title", weight: 1 }, { name: "subtitle", weight: 0.5 }] | ||
}; | ||
|
||
if (process.env.jb_search_customisation_file) { | ||
const customisationFilePath = path.join( | ||
process.env.HOME, | ||
process.env.jb_search_customisation_file | ||
); | ||
try { | ||
if (fs.existsSync(customisationFilePath)) { | ||
const customSearchOptions = JSON.parse( | ||
fs.readFileSync(customisationFilePath).toString() | ||
); | ||
fuseOptions = { | ||
...fuseOptions, | ||
...customSearchOptions | ||
}; | ||
} | ||
} catch (e) { | ||
// die silently | ||
if (alfy.debug) { | ||
console.error(e); | ||
} | ||
} | ||
} | ||
|
||
return fuseOptions; | ||
}; | ||
|
||
export default searchOptions; |