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

Desktop: Resolves #10549: Add exact search for title and body of notes #10991

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

pedr
Copy link
Collaborator

@pedr pedr commented Sep 6, 2024

Resolves #10549

Summary

On this PR I'm adding the possibility of using exact search for the title and body of notes using double quotes:

title: "2020-03-06"
title: "This is a note title with space" body: "Some other term to search"
etc

Changes:

  1. How the getTerm function works to allow search input after double quotes (explained better bellow)
  2. Created a function that splits the search input for title: and body: into phrases and words, escaping the necessary double quotes

Changes to getTerm

getTerm is a function responsible for taking a query like title: something body: another thing into

[
{ name: 'title', value: 'something' }, 
{ name: 'body', value: 'another thing' }
]

The problem was that an input like title: "something" other would be parsed as

[
{ name: 'title', value: 'something' }, 
{ name: 'text', value: 'other' }
]

I changed to associate the value after double quotes with the previous value until it finds another "term" (be it title, body, tag, etc):

// behaviour added on this PR
[
{ name: 'title', value: 'something' }, 
{ name: 'title', value: 'other' }
]

Changes in the current behaviour

As I described above, this PR changes some of the search behaviour. If, for example, the user might make a complex search like so:
title: "something" -other

it will be required to change the order of the elements

-other title: "something"

to have similar output.

Testing

I added some automated tests to the new functions, but the feature can also be tested manually:

  1. Create a note with "2024-05-06" in the title.
  2. Create a note with "2024-06-05" in the title.
  3. Search for: title: "2024-06-05"
  4. Should show only the note with the exact title

@pedr pedr requested a review from laurent22 September 6, 2024 22:45
@laurent22 laurent22 changed the title Desktop: Resolves ##10549: Add exact search for title and body of notes Desktop: Resolves #10549: Add exact search for title and body of notes Sep 7, 2024
@laurent22
Copy link
Owner

Thanks Pedro, but regarding this:

The problem was that an input like title: "something" other would be parsed as

[
{ name: 'title', value: 'something' },
{ name: 'text', value: 'other' }
]

That seems correct to me and I don't think we'd want to change this.

Doing an exact search for something like title: "2020-03-06" however makes sense

@laurent22
Copy link
Owner

laurent22 commented Sep 7, 2024

Also why was title: "2020-03-06" not working before? Is that because it was split on dashes? It's not very clear because none of your examples use the string that's causing a problem

@laurent22
Copy link
Owner

Also plenty of test errors on CI - did you try running the tests? It's very obvious that if you change the search engine you need to run all search-related tests (at the very least).

@pedr
Copy link
Collaborator Author

pedr commented Sep 9, 2024

Also why was title: "2020-03-06" not working before? Is that because it was split on dashes? It's not very clear because none of your examples use the string that's causing a problem

The problem is that the search seems dashes as word separators (and spaces and underslashes too). That means if you want to do an exact search with these characters you can't.

That means when you search for title: "2020-03-06" you get notes with title 2020-03-06 and 2020-06-05.

@pedr
Copy link
Collaborator Author

pedr commented Sep 21, 2024

  • Make more tests to ensure nothing is breaking
  • I probably don't need a types.ts file anymore, I can move SearchType to SeachEngine
  • Maybe it is not a good idea to pass SearchType to parseQuery?

@pedr
Copy link
Collaborator Author

pedr commented Sep 23, 2024

  • Maybe SearchType is not a good argument for querySearch (these languages use double quotes?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Title Search seems to return wrong results
3 participants