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

Add search by metadata #272

Open
lunaro-4 opened this issue Jun 10, 2024 · 3 comments
Open

Add search by metadata #272

lunaro-4 opened this issue Jun 10, 2024 · 3 comments
Labels
Priority: High An important issue requiring attention TagStudio: Library Relating to the TagStudio library system TagStudio: Search The TagStudio search engine Type: Enhancement New feature or request

Comments

@lunaro-4
Copy link

Similar issues

This feature is considered to be one of "Priority Features" by readme, yet I did not find any opened issues on that topic. Although I found a pull request #190, which could make use of parsing field names from search query.

Suggestions

I did not check contributing rules beforehand, so I accidentally started working on issue beforehand. Here is snippet from my fork:

    def parse_metadata(self, query: str | None = None) \
            -> list[dict[str, str | list[str]]]:
        """
        Splits query into several maps 'meta_key -> value'\n
        Values without specified key parsed as tags and put in 'unbound' key \n
        example query1:
            "meta_first: value; meta_second: value; tag1;\
 | meta_first: value; meta_second: value; notag;"
        example query2:
            "tag1 | notag | tag2"
        """
        if query is None:
            return {}
        meta_list: list = []
        meta_conditions = query.strip().split("|")
        for meta_condition in meta_conditions:
            meta_to_value: dict = {}
            field_data_list = meta_condition.strip().split(";")
            print(field_data_list)
            for field_data in field_data_list:
                field_parsed = field_data.strip().split(":")
                if len(field_parsed) < 2:
                    unbound_values = field_parsed[0].strip().split(' ')
                    if meta_to_value.get('unbound') is None:
                        meta_to_value['unbound'] = unbound_values
                    else:
                        meta_to_value['unbound'].append(unbound_values)
                    continue
                if len(field_parsed) != 2:
                    logging.warning("""[ERROR] Attempt to parse mutiple fields\
                                    as one! Do not forget to specify ';'\
                                    between different meta fields""")
                meta_to_value[field_parsed[0].lower()] = field_parsed[1].lower()
            meta_list.append(meta_to_value)

        logging.info("Parsed values: ",meta_list)
        return meta_list

Current state

I have tried to not touch much of code in Library.search_library, only add few new functions to allow additional entries to be filtered, but all other features should have stayed the same.

I planned to open a pull request straight up, but it is explicitly specified new issue to be opened beforehand, so let me know if is ok to go forward with this

@CyanVoxel CyanVoxel added Type: Enhancement New feature or request TagStudio: Library Relating to the TagStudio library system Priority: Medium An issue that shouldn't be be saved for last labels Jun 10, 2024
@CyanVoxel
Copy link
Member

Thank you for opening up an issue first, I really appreciate it!

This is definitely a much-needed feature. So if I'm understanding correctly, your approach is proposing syntax similar to the following?:
title: bookname Single search for "bookname" in Title field
author: authorname Single search for "authorname" in Author field
title: bookname; author: authorname Combined search for for "bookname" in Title field and search for "authorname" in Author field
content tags: tag1 Search for "tag1" in Content Tags field (this one may be tricky with spaces)

@lunaro-4
Copy link
Author

@CyanVoxel Yes, Your understanding is mostly correct. In currents state, tags are handled through 'unbound' category, since you already have them covered and I did not want to accidentally break anything)
For now, query with request would look like this:
tag1 tag2 no author; title: titlename; field1: fieldcontent;
So everything that does not have a word with ':' sign is processed as usual

@CyanVoxel
Copy link
Member

@CyanVoxel Yes, Your understanding is mostly correct. In currents state, tags are handled through 'unbound' category, since you already have them covered and I did not want to accidentally break anything) For now, query with request would look like this: tag1 tag2 no author; title: titlename; field1: fieldcontent; So everything that does not have a word with ':' sign is processed as usual

Sounds good! Thank you for working on this, and let me know if you have any questions!

@CyanVoxel CyanVoxel added the TagStudio: Search The TagStudio search engine label Jul 20, 2024
samuellieberman added a commit to samuellieberman/TagStudio that referenced this issue Jul 22, 2024
…StudioDev#272 and TagStudioDev#325)

Adds ability to check the existence of fields of any type using the following syntax:
```has_<field>```
```has_<field>:<True|False>```
Adds the ability to search the content of text_line and text_box fields using the following syntax:
```<field>:<text>```
(Replace whitespace with underscore _ in `text`)
Updated test_search.py for new behavior.
@CyanVoxel CyanVoxel added Priority: High An important issue requiring attention and removed Priority: Medium An issue that shouldn't be be saved for last labels Nov 8, 2024
@CyanVoxel CyanVoxel moved this to 🛠 Ready for Development in TagStudio Development Dec 21, 2024
@CyanVoxel CyanVoxel added this to the Alpha v9.5 (Post-SQL) milestone Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High An important issue requiring attention TagStudio: Library Relating to the TagStudio library system TagStudio: Search The TagStudio search engine Type: Enhancement New feature or request
Projects
Status: 🛠 Ready for Development
Development

No branches or pull requests

2 participants