lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From N Hira <>
Subject Re: Searching index problems with tomcat
Date Wed, 27 May 2009 20:12:09 GMT


1.  So you are creating a parser with { name, synonyms, propIn }, correct?

2.  Sorry -- I meant the output of "query.toString()"; I'm expecting to see something like
this when the sentence parameter is set to philipcimiano:
    name:philipcimiano synonyms:philipcimiano propIn:philipcimiano

3.  Out of curiosity, what is the value of topDocs.totalHits for your search?


----- Original Message ----
From: Marco Lazzara <>
Sent: Wednesday, May 27, 2009 2:41:44 PM
Subject: Re: Searching index problems with tomcat

I've made a bad copy-paste. this is the full class

The output of philipcimiano is  ex#pub1-author-ex#res2-name-philipcimiano
I've made a bad copy-paste. this is the full class

public class RDFinder {

    private Analyzer analyzer;
    private Directory directory;
    private IndexSearcher isearcher;
    private MultiFieldQueryParser parser;
    private Query query;
    private TreeMap<Integer,ArrayList<String>> resultingpaths;
    private PrintWriter outFile;

    public RDFinder(String indexpath, String[] indexField) throws
CorruptIndexException, IOException{

        //Creazione dell'oggetto per la ricerca indicando la struttura
(directory) su cui lavorare e l'analyzer
        analyzer = new StandardAnalyzer();
        directory = FSDirectory.getDirectory(indexpath);
        isearcher = new IndexSearcher(directory);
        parser = new MultiFieldQueryParser(indexField, analyzer);
        resultingpaths = new TreeMap<Integer,ArrayList<String>>();
        outFile = null;


   public TreeMap<Integer,ArrayList<String>> Search(String sentence, String
Field) throws ParseException, IOException{
       query = parser.parse(sentence);


         FileWriter fw = new FileWriter ("paths");
         BufferedWriter bw = new BufferedWriter (fw);
         outFile = new PrintWriter (bw);

         catch (FileNotFoundException exception){}
         catch (IOException exception){}

       //ArrayList<String> results = new ArrayList<String>();

     //Effettua la ricerca ottenendo l'oggetto TopDocs
        TopDocs topDocs =,1000);
        //Stampa del conteggio numero di hits.
        //System.out.println("Numero di hits " + topDocs.totalHits);

        //Array dei risultati
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        for (ScoreDoc sc : scoreDocs)
         //System.out.print(i++ + ": - ");
         //Attraverso l'oggetto scoreDoc e' possibile ottenere un indice che
passato all metodo
         //indexSearcher.doc restituisce un Document dal quale estrarre i
vari campi

         Field[] response = isearcher.doc(sc.doc).getFields(Field);
         //System.out.println("Risultato ");

         for (int k = 0; k <response.length; k++){
             String res = response[k].stringValue();
             if (!res.trim().equals(""))

                 res = res.toLowerCase();
                 int lung = CountChar(res, '-')+1;

                 //if (resultingpaths.containsKey(res.length()))
                 if (resultingpaths.containsKey(lung))
                 else {
                     ArrayList<String> respaths = new ArrayList<String>();
                     //resultingpaths.put(res.length(), respaths);
                     resultingpaths.put(lung, respaths);

         //codice che c'era prima
         /*String res = isearcher.doc(sc.doc).get(Field);
        return resultingpaths;

   public boolean Exists(String node) throws ParseException, IOException{

       query = parser.parse(node);

     //Effettua la ricerca ottenendo l'oggetto TopDocs
        TopDocs topDocs =,1);

        //Array dei risultati
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;

        return (scoreDocs.length >= 1);


   public String[] InputKeywords(String sentence){

       QueryTermVector QTV = new QueryTermVector(sentence, analyzer);
       return QTV.getTerms();


   public int CountChar(String s, char c){
       int count = 0;
       for (int i = 0; i < s.length(); i++)
           if (s.charAt(i) == c) count++;
       return count;


[ message truncated by -- too many replies ]

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message