Skip to main content

I’ve integrated box with my dotnet application, I’ve created folder via our application in box and after uploaded few files in the particular folder. After I tried to search that specific file with file name and parent folder id it returning empty result at the time of file uploaded, after few minutes(around 5-10 minutes) later when we try with the same API call, it bring the expected results. Please find the used code in below and suggest or share your thoughts. 

 

Client.SearchManager.QueryAsync(
                    fileName,
                    ancestorFolderIds: new List<string>() { parentFolderId },
                    fields: newÂ] { "id,name,type,path_collection,size,created_at,modified_at" },
                    limit: 30)

I’ve integrated box with my dotnet application, I’ve created folder via our application in box and after uploaded few files in the particular folder. After I tried to search that specific file with file name and parent folder id it returning empty result at the time of file uploaded, after few minutes(around 5-10 minutes) later when we try with the same API call, it bring the expected results. Please find the used code in below and suggest or share your thoughts. 

 

Client.SearchManager.QueryAsync(
                    fileName,
                    ancestorFolderIds: new List<string>() { parentFolderId },
                    fields: newÂ] { "id,name,type,path_collection,size,created_at,modified_at" },
                    limit: 30)

Hello, @Shankar 

 You’re experiencing a delay in the indexing process of newly uploaded files in Box, which is why your search results are initially empty but return the expected results after a few minutes. This is a known behavior with the Box API, as it can take some time for new files to be indexed and become searchable.

Possible Solutions and Workarounds
Polling Mechanism:
Implement a polling mechanism in your application to retry the search after a short delay. This can help ensure that the file is indexed and searchable before you perform the search operation.

int retryCount = 0;
const int maxRetries = 5;
const int delay = 2000; // 2 seconds

while (retryCount < maxRetries)
{
    var results = await Client.SearchManager.QueryAsync(
        fileName,
        ancestorFolderIds: new List<string>() { parentFolderId },
        fields: newt] { "id,name,type,path_collection,size,created_at,modified_at" },
        limit: 30);

    if (results.Entries.Any())
    {
        // File found
        break;
    }

    retryCount++;
    await Task.Delay(delay);
}
 

Event-Based Approach:
Use Box’s Webhooks to get notified when a file is uploaded and indexed. This way, you can trigger the search operation only after receiving the notification that the file is ready.
 

 

I hope this  info is helpful to you.

 

Best Regard,
Gregory Chavez


Hi Gregory Chavez,

 

 

Hope you’re doing great! first of all, thanks for your quick reply.

I’ve applied your suggested work around, but it’s also not working. The same time (around 8-10 minutes) it’ll take to bring the records from box while search.

As per current requirement, end user want to search instantly while they uploaded files. So, Event based approach how it’ll solve the requirements don’t know. Regarding this I’ll check with my team.

Do you have any alternate solution or any other suggestions for previous question please let me know for the conclusion.

 

Thanks,

Shankar

 


Hi Gregory Chavez,

 

 

Hope you’re doing great! first of all, thanks for your quick reply.

I’ve applied your suggested work around, but it’s also not working. The same time (around 8-10 minutes) it’ll take to bring the records from box while search.

As per current requirement, end user want to search instantly while they uploaded files. So, Event based approach how it’ll solve the requirements don’t know. Regarding this I’ll check with my team.

Do you have any alternate solution or any other suggestions for previous question please let me know for the conclusion.

 

Thanks,

Shankar Florida Blue

 

Hello, @Shankar 

Let’s explore some alternative solutions to improve the search performance:

1. Indexing
Description: Implement an indexing mechanism to speed up search queries. Indexing can significantly reduce the time it takes to retrieve records.
Implementation: Use a search engine like Elasticsearch or Solr to index the files as they are uploaded. This allows for near-instantaneous search results.
2. Database Optimization
Description: Optimize your database queries and structure to improve performance.
Implementation: Ensure that your database tables are properly indexed. Use query optimization techniques and consider denormalizing your database if necessary.
3. Caching
Description: Implement caching to store frequently accessed data temporarily.
Implementation: Use a caching solution like Redis or Memcached to cache search results. This can drastically reduce the load on your database and improve response times.
4. Asynchronous Processing
Description: Process file uploads and indexing asynchronously to avoid blocking the main thread.
Implementation: Use a message queue system like RabbitMQ or Kafka to handle file uploads and indexing in the background. This allows the main application to remain responsive.
5. Pagination and Lazy Loading
Description: Implement pagination and lazy loading to load data in chunks rather than all at once.
Implementation: Load a subset of search results initially and fetch more results as the user scrolls or navigates through the data.
6. Cloud-Based Solutions
Description: Utilize cloud-based search services that are optimized for performance.
Implementation: Services like AWS CloudSearch, Azure Cognitive Search, or Google Cloud Search can provide scalable and efficient search capabilities.
7. Profiling and Monitoring
Description: Profile and monitor your application to identify performance bottlenecks.
Implementation: Use profiling tools to analyze the performance of your application and identify areas that need optimization.

 

Best Regard,
Gregory Chavez

 


Reply