You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

qazimuneeb1's avatar
qazimuneeb1
Explorer | Level 3
4 years ago

Search text in Text File

I have an android app and I am having mp3 files in my dropbox and i am using search bar to type their name and get them using:

 

sresult = client.files().searchBuilder(path2, query2).withMode(mode).withMaxResults(max).withStart(stat).start();

Above feature is fulfilled but now i am having .txt files and i want to get text from those text files as i type a keyword in search bar. I used the above code for this feature but it gives me the exception:

class com.dropbox.core.v2.files.searcherrorexception exception in 2/files/search: {".tag":"path","path":"not_found"} 

 

Is it possible to do this in my app?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Yes, the Dropbox API does offer the ability to search for a particular query in a particular file type under a particular path. I see you're using searchBuilder though, which is deprecated, so you should update to searchV2Builder instead. The SearchV2Builder documentation shows what methods/parameters you can use.

     

    A 'not_found' error like you're getting indicates that there's nothing at the specified path, so make sure you're supplying a correct path value, in your code 'path2', for the connected account. I recommend reading the File Access Guide for information on interacting with the Dropbox filesystem via the API.

    • qazimuneeb1's avatar
      qazimuneeb1
      Explorer | Level 3

      I tried using this code:

      SearchV2Builder searchBuilder = client.files().searchV2Builder(query);
      List<String> fileExtensions = Arrays.asList(extensions);
      SearchOptions searchOptions = SearchOptions.newBuilder().withFileExtensions(fileExtensions).build();
      SearchV2Result searchResult = searchBuilder.withOptions(searchOptions).start();
      List<SearchMatchV2> searchMatches = searchResult.getMatches();

      but it only searches for text file name and not for the content placed inside it. Suppose i have a word "hello" placed inside my text file named "documents" so if i starts typing "he" then the word "hello" should appear in searches from "documents" file. Is the possible as i am having different text files and that should search in all of the text files before giving me the result  

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers797 PostsLatest Activity: 3 days ago
199 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!