Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed Jul 31, 2024
2 parents c34503f + 439150a commit ae39d3d
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 132 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v4
with:
version: 7.17.0
version: 9.3.0
run_install: true

- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "18.x"
cache: 'pnpm'
node-version: "20.x"

- name: Build
id: build
Expand All @@ -37,6 +40,18 @@ jobs:
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
- name: Generate a changelog
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: cliff.toml
args: --verbose
env:
GITHUB_REPO: ${{ github.repository }}

- name: Print the changelog
run: cat "${{ steps.git-cliff.outputs.changelog }}"

- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -46,7 +61,8 @@ jobs:
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
body: ${{ steps.git-cliff.outputs.changelog }}
draft: true
prerelease: false

- name: Upload zip file
Expand Down
12 changes: 12 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[changelog]
header = "Changelog"
body = """
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | upper_first }}
{% endfor %}
{% endfor %}
"""
trim = true
footer = "<!-- generated by git-cliff -->"
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scambier.obsidian-search",
"version": "1.23.1",
"version": "1.24.0-beta.3",
"description": "A search engine for Obsidian",
"main": "dist/main.js",
"scripts": {
Expand Down Expand Up @@ -52,6 +52,5 @@
"overrides": {
"moment@>=2.18.0 <2.29.4": ">=2.29.4"
}
},
"packageManager": "[email protected]+sha512.67f5879916a9293e5cf059c23853d571beaf4f753c707f40cb22bed5fb1578c6aad3b6c4107ccb3ba0b35be003eb621a16471ac836c87beb53f9d54bb4612724"
}
}
15 changes: 12 additions & 3 deletions src/__tests__/query-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ describe('The Query class', () => {

it('should correctly parse string queries', () => {
// Act
const query = new Query(stringQuery, { ignoreDiacritics: true })
const query = new Query(stringQuery, {
ignoreDiacritics: true,
ignoreArabicDiacritics: true,
})

// Assert
const segments = query.query.text
Expand All @@ -25,7 +28,10 @@ describe('The Query class', () => {

it('should not exclude words when there is no space before', () => {
// Act
const query = new Query('foo bar-baz', { ignoreDiacritics: true })
const query = new Query('foo bar-baz', {
ignoreDiacritics: true,
ignoreArabicDiacritics: true,
})

// Assert
expect(query.query.exclude.text).toHaveLength(0)
Expand All @@ -34,7 +40,10 @@ describe('The Query class', () => {
describe('.getExactTerms()', () => {
it('should an array of strings containg "exact" values', () => {
// Act
const query = new Query(stringQuery, { ignoreDiacritics: true })
const query = new Query(stringQuery, {
ignoreDiacritics: true,
ignoreArabicDiacritics: true,
})

// Assert
expect(query.getExactTerms()).toEqual(['lorem ipsum', 'sit amet'])
Expand Down
7 changes: 4 additions & 3 deletions src/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getAliasesFromMetadata,
getTagsFromMetadata,
isFileCanvas,
isFileFromDataloomPlugin,
isFileFromDataloom,
isFileImage,
isFileOffice,
isFilePDF,
Expand Down Expand Up @@ -136,7 +136,7 @@ export class CacheManager {
}

// ** Dataloom plugin **
else if (isFileFromDataloomPlugin(path)) {
else if (isFileFromDataloom(path)) {
try {
const data = JSON.parse(await app.vault.cachedRead(file))
// data is a json object, we recursively iterate the keys
Expand Down Expand Up @@ -230,10 +230,11 @@ export class CacheManager {
}
}
}

const displayTitle = metadata?.frontmatter?.[this.plugin.settings.displayTitle] ?? ''
const tags = getTagsFromMetadata(metadata)
return {
basename: file.basename,
displayTitle,
content,
/** Content without diacritics and markdown chars */
cleanedContent: stripMarkdownCharacters(removeDiacritics(content)),
Expand Down
1 change: 1 addition & 0 deletions src/components/ModalVault.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
}
query = new Query(searchQuery, {
ignoreDiacritics: plugin.settings.ignoreDiacritics,
ignoreArabicDiacritics: plugin.settings.ignoreArabicDiacritics,
})
cancelableQuery = cancelable(
new Promise(resolve => {
Expand Down
19 changes: 13 additions & 6 deletions src/components/ResultItemVault.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { ResultNote } from '../globals'
import {
getExtension,
isFileCanvas,
isFileCanvas, isFileExcalidraw,
isFileImage,
isFilePDF,
pathWithoutFilename,
Expand Down Expand Up @@ -36,19 +36,26 @@
$: cleanedContent = plugin.textProcessor.makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
$: glyph = false //cacheManager.getLiveDocument(note.path)?.doesNotExist
$: {
title = note.basename
title = note.displayTitle || note.basename
notePath = pathWithoutFilename(note.path)
// Icons
if (elFolderPathIcon) {
setIcon(elFolderPathIcon, 'folder-open')
}
if (elFilePathIcon) {
if (isFileImage(note.path)) setIcon(elFilePathIcon, 'image')
else if (isFilePDF(note.path)) setIcon(elFilePathIcon, 'file-text')
else if (isFileCanvas(note.path))
if (isFileImage(note.path)) {
setIcon(elFilePathIcon, 'image')
}
else if (isFilePDF(note.path)) {
setIcon(elFilePathIcon, 'file-text')
}
else if (isFileCanvas(note.path) || isFileExcalidraw(note.path)) {
setIcon(elFilePathIcon, 'layout-dashboard')
else setIcon(elFilePathIcon, 'file')
}
else {
setIcon(elFilePathIcon, 'file')
}
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract class OmnisearchModal extends Modal {
})

// Open in background
this.scope.register(['Alt'], 'O', e => {
this.scope.register(['Ctrl'], 'O', e => {
if (!isInputComposition()) {
// Check if the user is still typing
e.preventDefault()
Expand Down
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type DocumentRef = { path: string; mtime: number }
export type IndexedDocument = {
path: string
basename: string
displayTitle: string
mtime: number

content: string
Expand Down Expand Up @@ -76,6 +77,7 @@ export type ResultNote = {
score: number
path: string
basename: string
displayTitle: string
content: string
foundWords: string[]
matches: SearchMatch[]
Expand Down
17 changes: 12 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export default class OmnisearchPlugin extends Plugin {
})
)

this.refreshIndexCallback = this.notesIndexer.refreshIndex.bind(this.notesIndexer)
this.refreshIndexCallback = this.notesIndexer.refreshIndex.bind(
this.notesIndexer
)
addEventListener('blur', this.refreshIndexCallback)
removeEventListener

Expand Down Expand Up @@ -272,15 +274,20 @@ export default class OmnisearchPlugin extends Plugin {
indexingStep.set(IndexingStepType.WritingCache)

// Disable settings.useCache while writing the cache, in case it freezes
this.settings.useCache = false
await saveSettings(this)
const cacheEnabled = this.settings.useCache
if (cacheEnabled && !this.settings.DANGER_forceSaveCache) {
this.settings.useCache = false
await saveSettings(this)
}

// Write the cache
await searchEngine.writeToCache()

// Re-enable settings.caching
this.settings.useCache = true
await saveSettings(this)
if (cacheEnabled) {
this.settings.useCache = true
await saveSettings(this)
}
}

console.timeEnd('Omnisearch - Indexing total time')
Expand Down
7 changes: 4 additions & 3 deletions src/notes-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { removeAnchors } from './tools/notes'
import type { IndexedDocument } from './globals'
import {
isFileCanvas,
isFileFromDataloomPlugin,
isFileFromDataloom,
isFileImage,
isFilePDF,
logDebug,
Expand Down Expand Up @@ -51,7 +51,7 @@ export class NotesIndexer {
return (
this.isFilePlaintext(path) ||
isFileCanvas(path) ||
isFileFromDataloomPlugin(path) ||
isFileFromDataloom(path) ||
(canIndexPDF && isFilePDF(path)) ||
(canIndexImages && isFileImage(path)) ||
(canIndexImagesAI && isFileImage(path))
Expand All @@ -63,7 +63,7 @@ export class NotesIndexer {
this.canIndexUnsupportedFiles() ||
this.isFilePlaintext(path) ||
isFileCanvas(path) ||
isFileFromDataloomPlugin(path)
isFileFromDataloom(path)
)
}

Expand Down Expand Up @@ -91,6 +91,7 @@ export class NotesIndexer {
return {
path: filename,
basename: name,
displayTitle: '',
mtime: 0,

content: '',
Expand Down
4 changes: 2 additions & 2 deletions src/search/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class Query {
}
#inQuotes: string[]

constructor(text = '', options: { ignoreDiacritics: boolean }) {
constructor(text = '', options: { ignoreDiacritics: boolean, ignoreArabicDiacritics: boolean}) {
if (options.ignoreDiacritics) {
text = removeDiacritics(text)
text = removeDiacritics(text, options.ignoreArabicDiacritics)
}
const parsed = parse(text.toLowerCase(), {
tokenize: true,
Expand Down
12 changes: 9 additions & 3 deletions src/search/search-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ export class SearchEngine {
term.length <= 3 ? 0 : term.length <= 5 ? fuzziness / 2 : fuzziness,
boost: {
basename: settings.weightBasename,
directory: settings.weightDirectory,
aliases: settings.weightBasename,
displayTitle: settings.weightBasename,
directory: settings.weightDirectory,
headings1: settings.weightH1,
headings2: settings.weightH2,
headings3: settings.weightH3,
Expand Down Expand Up @@ -304,7 +305,12 @@ export class SearchEngine {
const title = document?.path.toLowerCase() ?? ''
const content = (document?.cleanedContent ?? '').toLowerCase()
return exactTerms.every(
q => content.includes(q) || removeDiacritics(title).includes(q)
q =>
content.includes(q) ||
removeDiacritics(
title,
this.plugin.settings.ignoreArabicDiacritics
).includes(q)
)
})
}
Expand Down Expand Up @@ -434,7 +440,7 @@ export class SearchEngine {
},
processTerm: (term: string) =>
(this.plugin.settings.ignoreDiacritics
? removeDiacritics(term)
? removeDiacritics(term, this.plugin.settings.ignoreArabicDiacritics)
: term
).toLowerCase(),
idField: 'path',
Expand Down
Loading

0 comments on commit ae39d3d

Please sign in to comment.