About SearchTupleSet

  • strubby

    strubby - 2013-03-29

    The other day I have successfully add the search in RadialGraphView to my GraphViewDemo. I am using the PrefixSearchTupleset, that means when I enter letter(s), nodes with the field I specified started with this letter(s) will highlighted, then I use KeyworldSearchTupleset and find out that : nodes with the field I specified equal to what i entered  will hightlighted.
    What I wanted is a Searcher: nodes with the field I specified contains with the letter I entered will hightlighted.    I know I have to construct other class familiar to the KeywordSearchTupleSet but I do not have any idea about this.
    I will apprciate for any of your anwser. I am looking forawrd to  your reply. 

  • Björn Kruse

    Björn Kruse - 2013-03-29

    Try RegexSearchTupleSet, it should fulfill your needs.
    If you don't konw regex (regular expressions) yet, do a few minutes googling and you will see they are really powerful.

    If you want to go beyond this (that is, to implement your own "ContainsSearchTupleSet"), then I cannot help much because I don't know the internals of this and I also don't know Lucene…

    best regards, Björn

  • strubby

    strubby - 2013-03-30

    Thank you , Björn.
    I have successfully fulfill my contain search by modified the RegexSearchTupleSet, Here lists as follows:
         * @see prefuse.data.search.SearchTupleSet#search(java.lang.String)
        public void search(String query) {
            if ( query == null )
                query = "";
            if ( !m_caseSensitive )
                query = query.toLowerCase();
            if ( query.equals(m_query) )
            Pattern pattern = null;
            try {
            String parseQuery = ".*"+query+".*";      
                pattern = Pattern.compile(parseQuery);  //modified here
            } catch ( Exception e ) {
                Logger logger = Logger.getLogger(this.getClass().getName());
                logger.warning("Pattern compile failed."
                        + "\n" + StringLib.getStackTrace(e));
            Tuple rem = clearInternal();   
            m_query = query;
            Iterator fields = m_source.keySet().iterator();
            while ( fields.hasNext() ) {
                String field = (String)fields.next();
                TupleSet ts = (TupleSet)m_source.get(field);
                Iterator tuples = ts.tuples();
                while ( tuples.hasNext() ) {
                    Tuple t = (Tuple)tuples.next();
                    String text = t.getString(field);
                    if ( !m_caseSensitive )
                        text = text.toLowerCase();
                    if ( pattern.matcher(text).matches() )
            Tuple add = getTupleCount() > 0 ? toArray() : null;
            fireTupleEvent(add, rem);

    But another question put it on me that when the search panel deleted to nothing, all the node are hightlighted. I knew someone else encounter similiar problem before, but I forgot how he solve it.
    Looking forward for all replies!

  • Björn Kruse

    Björn Kruse - 2013-03-30


    if your search field is empty (cleared), then query is "" (empty string), this leads to your query being ".*.*"
    That is a regex that matches everything :-)

    What about something like this?

    String parseQuery = "";
    if (! query=="")
        parseQuery = ".*"+query+".*";       
    pattern = Pattern.compile(parseQuery);  //modified here

    regards, Björn

  • strubby

    strubby - 2013-03-30

    Right. Problem solved, Thank you very much!


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks