Skip to content

Commit

Permalink
feat(search): support authors in search
Browse files Browse the repository at this point in the history
  • Loading branch information
sawhney17 committed Feb 6, 2023
1 parent c14ca5a commit 2302b06
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,14 @@ const SearchBar: React.FC<{ paperpileParsed }> = (paperpileParsed, uuid) => {
title: item.fields.title[0],
citekey: item.key,
// All authors joined into a single string
authors: item.fields.author
.map((author) => {
return author.literal;
})
.join(", "),
authors: item.fields.author.toString().toLowerCase().replaceAll(/,/g, ""),
abstract: item.fields.abstract,
};
} else {
pair = {
title: item.fields.title[0],
// All authors joined into a single string
authors: item.fields.author
.map((author) => {
return author.literal;
})
.join(", "),
authors: item.fields.author.toString().toLowerCase().replaceAll(/,/g, ""),
citekey: item.key,
};
}
Expand All @@ -94,7 +86,10 @@ const SearchBar: React.FC<{ paperpileParsed }> = (paperpileParsed, uuid) => {
if (!logseq.settings.smartsearch) {
results = smartblocks.filter((template) => {
if (template.fields.title[0] != undefined) {
return template.fields.title[0].toLowerCase().includes(searchTerm);
return (
template.fields.title[0].toLowerCase() +
template.fields.author.toString().toLowerCase().replaceAll(/,/g, "")
).includes(searchTerm);
}
});
} else {
Expand All @@ -114,7 +109,10 @@ const SearchBar: React.FC<{ paperpileParsed }> = (paperpileParsed, uuid) => {
} else {
results = smartblocks;
}
results.length = Math.min(results.length, logseq.settings.resultsCount || 100)
results.length = Math.min(
results.length,
logseq.settings.resultsCount || 100
);
setSearchResults(results);
}, [searchTerm]);
React.useEffect(() => {
Expand All @@ -136,9 +134,9 @@ const SearchBar: React.FC<{ paperpileParsed }> = (paperpileParsed, uuid) => {
}, [highlightedResult]);

const handleEnter = (index = null) => {
console.log(shouldEditAgain())
console.log(shouldEditAgain());
if (shouldEditAgain()) {
setEditAgain()
setEditAgain();
const resultKey = index == null ? highlightedResult : index;
if (resultKey != null) {
let citationDetails = searchRef.current[resultKey];
Expand Down Expand Up @@ -270,7 +268,7 @@ const SearchBar: React.FC<{ paperpileParsed }> = (paperpileParsed, uuid) => {
</li>
</div>
))}
{/* {searchResults.for((item, index) => (
{/* {searchResults.for((item, index) => (
<div
id={item.key}
onClick={() => {
Expand Down

0 comments on commit 2302b06

Please sign in to comment.