I’ve been working on implementing a search function using SearchConditions, but I’ve encountered an issue. Regardless of the filters I add (e.g., setting typed_value with datatype as Text and providing a specific value), the search still returns all objects in the vault instead of filtering them as expected.
Could you share an example or a model for correctly configuring the SearchConditions? I’d like to confirm whether my approach aligns with the API’s requirements. Thank you!
dashbords.js
function getDashBoardContent() {
return `
Search Objects by Title
Object Title :
Search
`;
}
// Event handler for initializing the dashboard
function OnNewDashboard(dashboard) {
dashboard.Events.Register(MFiles.Event.Started, async () => {
const htmlContent = getDashBoardContent();
const mainContent = document.getElementById("Main");
mainContent.innerHTML = htmlContent;
mainContent.style.display = "block";
// Attach event to the search button
const btnSearch = document.getElementById("btnSearch");
btnSearch.addEventListener("click", async () => {
const title = document.getElementById("objectTitle").value;
await searchObjectsByTitle(dashboard.ShellFrame.ShellUI, title);
});
});
}
// Perform the search by title
async function searchObjectsByTitle(shellUI, title) {
try {
// Definește condițiile de căutare
const searchConditions = [
{
type: 1, // CONDITION_TYPE_EQUALS
expression: {
type: 7, // ExpressionType.PropertyValue
data: {
property_value: {
property_def: 0, // NameOrTitle (ID-ul proprietății)
typed_value: {
text: title
}
}
},
indirection_levels: []
}
}
];
console.log(JSON.stringify(searchConditions, null, 2));
// Execută căutarea
const searchResults = await shellUI.Vault.SearchOperations.SearchObjects({
call_importance: 1,
target: { mode: 0 },
conditions: searchConditions,
limit: 500,
timeout_in_seconds: 30,
sorting: {
rules: { values: [] },
options: { allow_resorting_to_default_sort: false },
},
});
// Gestionează rezultatele
if (searchResults.results.length > 0) {
displayResults(searchResults);
console.log("Obiect găsit:", searchResults.results[0]);
} else {
console.log("Niciun obiect găsit pentru titlul:", title);
}
} catch (error) {
console.error("Eroare la căutare:", error);
}
}
// Display the search results
function displayResults(results) {
const resultsContainer = document.getElementById("searchResults");
if (!results || results.results.length === 0) {
resultsContainer.innerHTML = " No results found. ";
} else {
const resultList = [];
for (let i = 0; i ${results.results[i].object.version_info.title} `
);
}
resultsContainer.innerHTML = resultList.join('');
}
}
// Function to display error messages
function showErrorMessage(errorMessage) {
const errorMessageElement = document.getElementById("error_message");
errorMessageElement.innerHTML = errorMessage;
}