Searchable improvement

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Searchable improvement

Postby nicola.gioia » Tue Jul 25, 2006 8:40 am

With existing API is possible to get programmatically the index on which a String will be inserted without insert them.
This should be usefull for example in a Dictionary listed in a JList on which we want to see the nearest word of a new word that should be inserted in the dictionary, but before to insert them.
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby JIDE Support » Tue Jul 25, 2006 3:26 pm

I think it should be possible with current APIs. For example, you can use findFirst(String s) to find the insert location from a list.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby nicola.gioia » Fri Jul 28, 2006 2:22 am

Yes it is possible, but i must use the findNext function using all the prefix until the result of the findNext is -1 or i reached the end of the String to search.
Thanks
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby JIDE Support » Fri Jul 28, 2006 3:48 am

I re-thought about this. I don't think Searchable is a good candidate for this. The reason is Searchable doesn't assume the list is sorted. However to do what you want, it'd better to assume the list is sorted.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby nicola.gioia » Fri Jul 28, 2006 8:42 am

Sorry I forget to tell that the list on which I must find the future position of the string is a sorted list, elsewere the problem is inexistent.
I have a sorted searcheable JList with about 200000 sorted words and I must highlight the two word that will surround a new word before it we will be added.
I tried to use the subsequent code:
Code: Select all
   protected int searchNearestElement(ListSearchable list,String text) {
      int ret = 0;
      int temp = 0;
      int index = 0;
      list.setCursor(0);
      while(temp >=0 && index < text.length()) {
         temp = list.findNext(text.substring(0, index+1));
         
         if(temp!= -1)
            ret = temp;
         
         index++;
      }
      
      return ret;
   }


But this don't fine in case of a list containing:
customise
customize
customized
customizing
customs


when we try to search the word
customizzation
because the algorithm find the index of customize word instead of the index of customizing
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby JIDE Support » Fri Jul 28, 2006 2:43 pm

Anyway, I don't think it worth the effort to adapt Searchable interface for this purpose. Searchable uses brute-force searching as it assumes the list is not sorted. So it's not the most efficient way. You can easily do this using a bi-search algorithm. So just write your own code to do it.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 77 guests