Lucene - Simple search with query

Asked

Viewed 114 times

1

I am trying to search on an index made with Lucene that was sent to me. These are simple searches that are not working...

package portugues;

//https://lucene.apache.org/core/2_9_4/queryparsersyntax.html

import java.nio.file.Paths;

import javax.management.Query;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.FSDirectory;

public class Buscador {

    public static void main(String[] args) {

    IndexReader reader =   DirectoryReader.open(FSDirectory.open(Paths.get("/home/janaina/Bureau/projet_java/MyLuceneIndex")));
    IndexSearcher searcher = new IndexSearcher(reader);
    Analyzer analyzer = new StandardAnalyzer();
    QueryParser parser = new QueryParser("contents", analyzer);
    Query query1 = parser.parse("pomme");
    Query query2 = parser.parse("pomme" AND "banane");
    Query query3 = parser.parse("pomme" OR "banane");
    Query query4 = parser.parse("pomme*");


    System.out.println(query1);
    System.out.println(query2);
    System.out.println(query3);
    System.out.println(query4);

}

}

I just need to find a few words using Query Parser Syntax. Sorry if the question is stupid. I’m just a beginner... Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.