Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene full-text search
    primarykey
    data
    text
    <p>I am using Lucene 3.3.0 with java. I am facing the following problem and don know if there exits a solution for it.</p> <p>I index the following text: "The boy played so hard to win the game" using StandardAnalyzer, and then i make a query search using "play" ... Lucene find hits ONLY when i use WildcardQuery builder.</p> <p>The problem is that when i try searching "boy game" it finds NO hits at all.</p> <p>Is there away to make Lucene make something like context searching to solve this problem ?</p> <p>Thanks, Samer</p> <pre><code>private static void addDoc(IndexWriter w, String value) throws IOException { Document doc = new Document(); doc.add(new Field("title", value, Field.Store.YES, Field.Index.ANALYZED)); w.addDocument(doc); } @SuppressWarnings("deprecation") public static void lucene(String args, String query) throws IOException, ParseException { // 0. Specify the analyzer for tokenizing text. // The same analyzer should be used for indexing and searching StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT); // 1. create the index Directory index = new RAMDirectory(); // the boolean arg in the IndexWriter ctor means to // create a new index, overwriting any existing index IndexWriter w = new IndexWriter(index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); String[] splitOnLinefeed = args.split("\n"); for (int i = 0; i &lt; splitOnLinefeed.length; i++) { addDoc(w, splitOnLinefeed[i]); } w.close(); // 2. query String querystr = query+"*"; // the "title" arg specifies the default field to use // when no field is explicitly specified in the query. Query q = new QueryParser(Version.LUCENE_CURRENT, "title", analyzer) .parse(querystr); // 3. search IndexSearcher searcher = new IndexSearcher(index, true); ScoreDoc[] hits = searcher.search(q, 100).scoreDocs; // 4. display results System.out.println("Found " + hits.length + " hit(s)."); for (int i = 0; i &lt; hits.length; ++i) { int docId = hits[i].doc; Document d = searcher.doc(docId); System.out.println((i + 1) + ". " + d.get("title")); } // searcher can only be closed when there // is no need to access the documents any more. searcher.close(); } public static void main(String[] args) throws Exception { lucene(parse("Test.pdf"), "boy game"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload