Add similar app recommendations from shared categories
This commit is contained in:
@@ -1869,6 +1869,51 @@ impl Database {
|
||||
)
|
||||
}
|
||||
|
||||
// --- Similar apps ---
|
||||
|
||||
/// Find AppImages from the user's library that share categories with the given app.
|
||||
pub fn find_similar_apps(
|
||||
&self,
|
||||
categories: &str,
|
||||
exclude_id: i64,
|
||||
limit: i32,
|
||||
) -> SqlResult<Vec<(i64, String, Option<String>)>> {
|
||||
// Split categories and match any overlap
|
||||
let cats: Vec<&str> = categories.split(';').filter(|s| !s.is_empty()).collect();
|
||||
if cats.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
// Build LIKE conditions for each category
|
||||
let conditions: Vec<String> = cats.iter()
|
||||
.map(|c| format!("categories LIKE '%{}%'", c.replace('\'', "''")))
|
||||
.collect();
|
||||
let where_clause = conditions.join(" OR ");
|
||||
|
||||
let sql = format!(
|
||||
"SELECT id, COALESCE(app_name, filename) AS name, icon_path
|
||||
FROM appimages
|
||||
WHERE id != ?1 AND ({})
|
||||
LIMIT ?2",
|
||||
where_clause
|
||||
);
|
||||
|
||||
let mut stmt = self.conn.prepare(&sql)?;
|
||||
let rows = stmt.query_map(params![exclude_id, limit], |row| {
|
||||
Ok((
|
||||
row.get::<_, i64>(0)?,
|
||||
row.get::<_, String>(1)?,
|
||||
row.get::<_, Option<String>>(2)?,
|
||||
))
|
||||
})?;
|
||||
|
||||
let mut results = Vec::new();
|
||||
for row in rows {
|
||||
results.push(row?);
|
||||
}
|
||||
Ok(results)
|
||||
}
|
||||
|
||||
// --- System modification tracking ---
|
||||
|
||||
pub fn register_modification(
|
||||
|
||||
Reference in New Issue
Block a user