Forum Discussion

qazimuneeb1's avatar
qazimuneeb1
Explorer | Level 3
5 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?

3 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    5 years ago

    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
    5 years ago

    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 developers

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!