Skip to content

Commit

Permalink
♻️ Rework search to use basename instead of fullpath
Browse files Browse the repository at this point in the history
  • Loading branch information
bchatard committed Jan 7, 2020
1 parent fec9df7 commit 9443f6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ if (items.length) {
} else {
const pattern = new RegExp(query, "i");
const search = item =>
pattern.test(item.title) || pattern.test(item.subtitle);
pattern.test(item.title) ||
pattern.test(item.variables.jb_search_basename);
matchItems = alfy.matches(query, items, search);
matchTime = new Date();
}
Expand Down
8 changes: 5 additions & 3 deletions src/project.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const alfy = require("alfy");
const path = require("path");

const projectPaths = require("./project/paths");
const projectName = require("./project/name");
Expand All @@ -21,7 +22,8 @@ const buildItem = (product, name, projectPath) => {
},
variables: {
jb_project_name: name,
jb_bin: product.binPath
jb_bin: product.binPath,
jb_search_basename: path.basename(projectPath)
}
};
};
Expand All @@ -40,8 +42,8 @@ const getItems = product => {
if (!cachedProjects) {
const projects = [];
const paths = projectPaths.get(product.preferencePath);
paths.forEach(path => {
const item = buildProductItem(product, path);
paths.forEach(_path => {
const item = buildProductItem(product, _path);
if (item) {
projects.push(item);
}
Expand Down
5 changes: 4 additions & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const searchOptions = () => {
distance: 80,
maxPatternLength: 32,
minMatchCharLength: 2,
keys: [{ name: "title", weight: 1 }, { name: "subtitle", weight: 0.5 }]
keys: [
{ name: "title", weight: 1 },
{ name: "variables.jb_search_basename", weight: 0.5 }
]
};

if (process.env.jb_search_customisation_file) {
Expand Down

0 comments on commit 9443f6f

Please sign in to comment.