Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global search accepts regex #169

Closed
alexn-s opened this issue Jun 26, 2022 · 3 comments
Closed

global search accepts regex #169

alexn-s opened this issue Jun 26, 2022 · 3 comments
Assignees
Labels
subtask dependent on another open issue

Comments

@alexn-s
Copy link

alexn-s commented Jun 26, 2022

Describe the solution you'd like
often i want to exclude something from the search or see everything except ....

ideas

  • either a second search bar for excluding keywords/ text
  • support for regex
  • NOT / ! keyword to negate the search
@RafaelGB
Copy link
Owner

Could be a subtask of #73

When the v8 of react-table will be available, we need to improve the search input yep :)
thanks for your idea

@RafaelGB RafaelGB added the subtask dependent on another open issue label Jun 26, 2022
@alexn-s
Copy link
Author

alexn-s commented Jun 26, 2022

you are right. had not seen that feature.

anyway awesome work with your extension.
it really is the most important one for me since i found it to quickly filter through my multiple thousand notes.
i really appreciate it 💖

@RafaelGB RafaelGB added wontfix This will not be worked on and removed wontfix This will not be worked on labels Sep 11, 2022
@RafaelGB
Copy link
Owner

The idea will be support regex

import { FilterFn, Row } from "@tanstack/react-table"
import { RowDataType } from "cdm/FolderModel"
import { LocalSettings } from "cdm/SettingsModel";
import { InputType } from "helpers/Constants";
import { Literal } from "obsidian-dataview";
import { DataviewService } from "services/DataviewService";

export const globalDatabaseFilterFn: (ddbbConfig: LocalSettings) => FilterFn<RowDataType> = (ddbbConfig: LocalSettings) => (
    row: Row<RowDataType>,
    columnId: string,
    filterValue: string
) => {
    const value = row.getValue<Literal>(columnId);
    if (value === undefined) {
        return false;
    }
    const sanitized = DataviewService.parseLiteral(value, InputType.MARKDOWN, ddbbConfig, true).toString().toLowerCase();
    filterValue = filterValue.toLowerCase();
    return sanitized.includes(filterValue) || searchRegex(sanitized, filterValue);
}

function searchRegex(sanitized: string, filterValue: string): boolean {
    try {
        const regex = new RegExp(filterValue);
        return regex.test(sanitized);
    } catch (e) {
        return false;
    }
}

@RafaelGB RafaelGB self-assigned this Sep 11, 2022
@RafaelGB RafaelGB changed the title exclude from search global search accepts regex Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subtask dependent on another open issue
Projects
None yet
Development

No branches or pull requests

2 participants