Changeset 12387


Ignore:
Timestamp:
2006-08-02T17:21:57+12:00 (18 years ago)
Author:
mdewsnip
Message:

Fixes for fuzzy searching, many thanks to John Thompson and DL Consulting Ltd.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java

    r12377 r12387  
    8989        ///ystem.err.println("**** query = " + query_string);
    9090
    91         Query query = query_parser.parse(query_string);
    92         query = query.rewrite(reader);
    9391        Query query_including_stop_words = query_parser_no_stop_words.parse(query_string);
    9492        query_including_stop_words = query_including_stop_words.rewrite(reader);
     93
     94                // Split query string into the search terms and the filter terms
     95                // * The first +(...) term contains the search terms so count
     96                //   up '(' and stop when we finish matching ')'
     97                int offset = 0;
     98                int paren_count = 0;
     99                boolean seen_paren = false;
     100                while (offset < query_string.length() && (!seen_paren || paren_count > 0))
     101                    {
     102                        if (query_string.charAt(offset) == '(')
     103                            {
     104                                paren_count++;
     105                                seen_paren = true;
     106                            }
     107                        if (query_string.charAt(offset) == ')')
     108                            {
     109                                paren_count--;
     110                            }
     111                        offset++;
     112                    }
     113                String query_prefix = query_string.substring(0, offset);
     114                String query_suffix = query_string.substring(offset);
     115
     116                ///ystem.err.println("Prefix: " + query_prefix);
     117                ///ystem.err.println("Suffix: " + query_suffix);
     118
     119        Query query = query_parser.parse(query_prefix);
     120        query = query.rewrite(reader);
    95121
    96122                // If this is a fuzzy search, then we need to add the fuzzy
     
    112138                            {
    113139                                char c = mutable_query_string.charAt(o);
    114                                 ///ystem.err.println("SM: in state " + s + " and reading a " + c);
    115140                                if (s == 0 && c == 'T')
    116141                                    {
     
    153178                                        // fuzzy search indicator
    154179                                        // Nor outside the scope of parentheses
    155                                         if (Character.isWhitespace(c) || c == ')')
     180                                        else if (Character.isWhitespace(c) || c == ')')
    156181                                            {
    157182                                                ///ystem.err.println("Yahoo! Found fuzzy term.");
     
    170195                            }
    171196                        // Reparse the query
    172                         ///ystem.err.println("Fuzzy query: " + mutable_query_string.toString());
    173                         query = query_parser.parse(mutable_query_string.toString());
     197                        ///ystem.err.println("Fuzzy query: " + mutable_query_string.toString() + query_suffix);
     198                        query = query_parser.parse(mutable_query_string.toString() + query_suffix);
    174199                        // And rewrite again
    175200                        query = query.rewrite(reader);
  • trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java

    r12377 r12387  
    8989        ///ystem.err.println("**** query = " + query_string);
    9090
    91         Query query = query_parser.parse(query_string);
    92         query = query.rewrite(reader);
    9391        Query query_including_stop_words = query_parser_no_stop_words.parse(query_string);
    9492        query_including_stop_words = query_including_stop_words.rewrite(reader);
     93
     94                // Split query string into the search terms and the filter terms
     95                // * The first +(...) term contains the search terms so count
     96                //   up '(' and stop when we finish matching ')'
     97                int offset = 0;
     98                int paren_count = 0;
     99                boolean seen_paren = false;
     100                while (offset < query_string.length() && (!seen_paren || paren_count > 0))
     101                    {
     102                        if (query_string.charAt(offset) == '(')
     103                            {
     104                                paren_count++;
     105                                seen_paren = true;
     106                            }
     107                        if (query_string.charAt(offset) == ')')
     108                            {
     109                                paren_count--;
     110                            }
     111                        offset++;
     112                    }
     113                String query_prefix = query_string.substring(0, offset);
     114                String query_suffix = query_string.substring(offset);
     115
     116                ///ystem.err.println("Prefix: " + query_prefix);
     117                ///ystem.err.println("Suffix: " + query_suffix);
     118
     119        Query query = query_parser.parse(query_prefix);
     120        query = query.rewrite(reader);
    95121
    96122                // If this is a fuzzy search, then we need to add the fuzzy
     
    112138                            {
    113139                                char c = mutable_query_string.charAt(o);
    114                                 ///ystem.err.println("SM: in state " + s + " and reading a " + c);
    115140                                if (s == 0 && c == 'T')
    116141                                    {
     
    153178                                        // fuzzy search indicator
    154179                                        // Nor outside the scope of parentheses
    155                                         if (Character.isWhitespace(c) || c == ')')
     180                                        else if (Character.isWhitespace(c) || c == ')')
    156181                                            {
    157182                                                ///ystem.err.println("Yahoo! Found fuzzy term.");
     
    170195                            }
    171196                        // Reparse the query
    172                         ///ystem.err.println("Fuzzy query: " + mutable_query_string.toString());
    173                         query = query_parser.parse(mutable_query_string.toString());
     197                        ///ystem.err.println("Fuzzy query: " + mutable_query_string.toString() + query_suffix);
     198                        query = query_parser.parse(mutable_query_string.toString() + query_suffix);
    174199                        // And rewrite again
    175200                        query = query.rewrite(reader);
Note: See TracChangeset for help on using the changeset viewer.