Java Mailing List Archive

http://www.java2.5341.com/

Home » java-user.lucene »

Strange behaviour of FrenchAnalyzer when using accents

lamino

2008-11-07

Replies: Find Java Web Hosting

Author LoginPost Reply

Greetings,

I'm getting a strange behaviour when using the FrenchAnalyzer.

Calling the same class (Searcher.java, see below) from a JSP file and from a
Java class, gives differents results when the query contains accents !

Notice the different value of the query object :

q = "secrétaire"

If calling from main.jsp query = text:secrétair
If calling from main.java query = text:secretair


Source code (Search.java, Main.jsp, Main.java) :

public void search() {

    String q = "secrétaire";
    String indexDirectory = "c:\\temp\\accent\\index2";
 
    try {
       IndexSearcher searcher = new IndexSearcher(indexDirectory);
       QueryParser parser = new QueryParser("text", new
FrenchAnalyzer());
       Query query = parser.parse(q);
       Hits hits = searcher.search(query);
     
       System.out.println(query);
     
     
       System.out.println("Results for '" + q + "': " +
hits.length());
     
       Iterator iter = hits.iterator();
       while (iter.hasNext()) {
          Hit hit = (Hit) iter.next();
          Document doc = hit.getDocument();
       }
     
    } catch (Exception e) {
    }
 
  }

=====================Main.jsp=====================

<%        
       Search s = new Search();                                    
       s.search();    
%>

OUPUT :
text:secrétair
Results for 'secrétaire': 0


=====================Main.java=====================


public class Main {
 
  public static void main(String[] args) {                                  

    Search s = new Search();      
    s.search();
     
  }      
}

OUTPUT :
text:secretair
Results for 'secrétaire': 1

I will appreciate your help, thank you in advance.

Lamine

--
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@(protected)
For additional commands, e-mail: java-user-help@(protected)

©2008 java2.5341.com - Jax Systems, LLC, U.S.A.