Skip to content

feat: support & as AND operator in search - #96

Open
legentpc wants to merge 1 commit into
OperationPotato:masterfrom
legentpc:mm-search
Open

feat: support & as AND operator in search#96
legentpc wants to merge 1 commit into
OperationPotato:masterfrom
legentpc:mm-search

Conversation

@legentpc

Copy link
Copy Markdown
Contributor

What

Added & to search. Terms joined with | match items containing any of them (unchanged),
While terms joined with & match only items that contain all of them. Example: Hecatomb X & Last Stand V highlights only the item that has both names. Works in the item list and in the container search (double-click on the search bar).

Changelog New Features

  • Added & operator to search, which only matches items that contain all searched terms.
    • Hecatomb X & Last Stand V highlights only the item that has both names; works in the item list and container search (double-click).
    • Can be mixed with |: a & b | c means (a AND b) OR c.

Changelog Technical Details

  • Search terms are now parsed into OR groups (|) of AND terms (&) and matched as OR-of-ANDs.
  • isDistinctSearch compares the group structure, so changing an operator mid-search re-filters from the full list.
  • & is highlighted in the search bar, just like |.

@j10a1n15 j10a1n15 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pr title doesnt match the sh template

Comment on lines 39 to +40
'|'.code -> style = style.withColor(CommonColors.SOFT_YELLOW)
'&'.code -> style = style.withColor(CommonColors.SOFT_YELLOW)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'|'.code -> style = style.withColor(CommonColors.SOFT_YELLOW)
'&'.code -> style = style.withColor(CommonColors.SOFT_YELLOW)
'|'.code, '&'.code -> style = style.withColor(CommonColors.SOFT_YELLOW)

Comment on lines +20 to +25
aFilter.forEachIndexed { index, aGroup ->
val bGroup = bFilter[index]
if (bGroup.size != aGroup.size) return true
aGroup.forEachIndexed { i, aSearch ->
if (!bGroup[i].startsWith(aSearch)) return true
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aFilter.forEachIndexed { index, aGroup ->
val bGroup = bFilter[index]
if (bGroup.size != aGroup.size) return true
aGroup.forEachIndexed { i, aSearch ->
if (!bGroup[i].startsWith(aSearch)) return true
}
aFilter.forEachIndexed { filterIndex, aGroup ->
val bGroup = bFilter[filterIndex]
if (bGroup.size != aGroup.size) return true
aGroup.forEachIndexed { groupIndex, aSearch ->
if (!bGroup[groupIndex].startsWith(aSearch)) return true
}

@j10a1n15 j10a1n15 linked an issue Aug 24, 2026 that may be closed by this pull request

@j10a1n15 j10a1n15 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider adding something similar to this instead of the List<List>, we aren't really in favour of this

Image
The Code
interface Search {
	fun matches(stackName: String, loreLines: List<String>): Boolean
}

data class TermSearch(val term: String) : Search {
	override fun matches(stackName: String, loreLines: List<String>): Boolean {
		return stackName.contains(term) || loreLines.any { line -> line.contains(term) }
	}
}

data class AndSearch(val conditions: List<Search>) : Search {
	override fun matches(stackName: String, loreLines: List<String>): Boolean {
		return conditions.all { condition -> condition.matches(stackName, loreLines) }
	}
}

data class OrSearch(val conditions: List<Search>) : Search {
	override fun matches(stackName: String, loreLines: List<String>): Boolean {
		return conditions.any { condition -> condition.matches(stackName, loreLines) }
	}
}

Or take the code from this unmerged branch: master...feat/search-improvements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi search

2 participants