Ok. There is a piece of code attached.. As I already said, I want to pass
that when the term "Lucene in Action" he finds only the 1st sentence.




2010/4/10 Shai Erera <ser...@gmail.com>

> Hi. I'm not sure I understand what you searched for. When you search
> for "Lucene in action", do you search it with the quotes or not? If
> with the quotes, then I don't understand how the 2nd dox is found.
>
> Do you perhaps have a test code you can share w/ us? It can be a short
> and simple main which creates an index w/ some documents and then
> searches them.
>
> Shai
>
> On Saturday, April 10, 2010, Fotos fotos <railan.xi...@gmail.com> wrote:
> > Hello!
> > I am a beginner with Lucene. I'm needing to do the following:
> >
> > I have a text file with the following terms:
> >
> > "Lucene in action"
> > "Lucene"
> >
> > and a file with the following sentences:
> >
> > 1 - "Lucene in action now."
> > 2 - "Lucene for Dummies"
> > 3 - "Managing Gigabytes"
> >
> > I need to search in phrases of doc2, the terms of doc1.
> >
> > But in search of the word n-grama: "Lucene in Action", he also finds the
> 2nd
> > sentence.
> >
> > In this case, I want to meet with the term 1 ("Lucene in Action"), only
> the
> > first phrase and remove the term of the index, for not to be found when I
> > pass the term 2 ("Lucene")
> >
> > Railan Xisto
> > Web Developer
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
>
>
public class Main {
        
        public static void main(String[] args) throws CorruptIndexException, 
LockObtainFailedException, IOException, ParseException{ 
        // Cria o analyzador  
           StandardAnalyzer analyzer = new 
StandardAnalyzer(Version.LUCENE_CURRENT);  
             
           // Diretório virtual para o índice  
           Directory indexDirectory = new RAMDirectory();  


              
           // Cria o arquivo com tamanho ilimitado.  
          
           IndexWriter w = new IndexWriter(indexDirectory, analyzer, true, 
IndexWriter.MaxFieldLength.UNLIMITED);
           // Adiciona 4 documentos.  
           addDoc(w, "Lucene in Action now. Lucene is a tool");   
           addDoc(w, "Lucene for Dummies");  
          
            
          // Fecha o arquivo.  
           w.close();  
           
          File arquivo;
          arquivo = new File("Docs/documento.txt"); /document where are the 
terms for the search
          FileInputStream fis = new FileInputStream(arquivo);  //open the file 
in memory
         
      int ln;  
      String termos = "";
      
     
      
     while ( (ln = fis.read()) !=-1 ) {  // read the file
          
          termos = termos + ( (char)ln );      
     }  
      
  
      fis.close();
              
           // Faz o parse da consulta e cria uma query do lucene.  
           Query q = new QueryParser(Version.LUCENE_CURRENT, "title", 
analyzer).parse(termos); 


           
           int maxHits = 10;  
              
            // Cria o acesso ao índice  
            IndexSearcher searcher = new IndexSearcher(indexDirectory);  
             // Prepara a coleção de resultado  
             TopScoreDocCollector collector = 
TopScoreDocCollector.create(maxHits, true); 
           
               
             // Faz a pesquisa  
             searcher.search(q, collector);  
              
             // Separa os 10 itens mais relevantes para a consulta.  
             ScoreDoc[] hits = collector.topDocs().scoreDocs;
            
              // Imprime os documentos retornados.  
              System.out.println("Found " + hits.length + " hits.");  
              for (int i = 0; i < hits.length; ++i) {  
                  int docId = hits[i].doc;  
                  Document d = searcher.doc(docId);  
                  System.out.println((i + 1) + ". " + d.get("title"));  
              } 
              
        
}  
 
   private static void addDoc(IndexWriter w,String text) throws IOException {  
                Document doc = new Document();  
                doc.add(new Field("title", text, Field.Store.YES, 
Field.Index.ANALYZED));  
                w.addDocument(doc);  
   } 
  
}
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to