lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: lucene 4.3 search not working ShingleAnalyzerWrapper
Date Mon, 23 Sep 2013 11:58:01 GMT
What Query is actually parsed?

Mike McCandless

http://blog.mikemccandless.com


On Sat, Sep 21, 2013 at 8:48 PM, illusionz <deep.illusionz@gmail.com> wrote:
> Hi Michael,
>
> I am getting no hits.
>
> Tokens are generated in this form : iam, amleagend
>
>  I am searching from "amleagend", and getting no hits.
>
> Thanks,
> Depanker Sharma
>
>
>
>
> On Sat, Sep 21, 2013 at 10:38 PM, Michael McCandless <
> lucene@mikemccandless.com> wrote:
>
>> What's actually going wrong?  Exception?  No hits?
>>
>> What query is actually being executed?  Ie what does that
>> System.out.println print?
>>
>> If you search for i am leagend instead does it still find no hits?
>>
>> Mike McCandless
>>
>> http://blog.mikemccandless.com
>>
>>
>> On Sat, Sep 21, 2013 at 2:48 AM, illusionz <deep.illusionz@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > I am learning lucene, and have created indexes using LuceneWriter (which
>> > worked fine), but when I try an query it with LuceneReader it dose not
>> > work, need help on the same.  Following is the code for LuceneWriter.java
>> > and LuceneReader.java:
>> >
>> >
>> > public class LuceneWriter {
>> >  public static void main(String[] arg) throws IOException
>> > {
>> > File docDir = new File(DataConfig.dataDir);
>> >  Directory dir =  FSDirectory.open(docDir);
>> > HashMap<String, Analyzer> documentFiledAnalysers = new HashMap<String,
>> > Analyzer>();
>> >  documentFiledAnalysers.put("id", new
>> StandardAnalyzer(Version.LUCENE_43));
>> >  documentFiledAnalysers.put("content", new ShingleAnalyzerWrapper(new
>> > StandardAnalyzer(Version.LUCENE_43), 2, 2, "", false, true));
>> >  PerFieldAnalyzerWrapper analyserWrapper = new
>> PerFieldAnalyzerWrapper(new
>> > StandardAnalyzer(Version.LUCENE_43), documentFiledAnalysers);
>> >  IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_43,
>> > analyserWrapper);
>> >  iwc.setOpenMode(OpenMode.CREATE);
>> >  IndexWriter writer =  new IndexWriter(dir, iwc);
>> >  Document doc2 = new Document();
>> > doc2.add(new StringField("id", "2", Field.Store.YES));
>> > doc2.add(new StringField("content", "I am leagend",
>> > Field.Store.<http://field.store.no/>
>> > YES));
>> >  Document doc3 = new Document();
>> > doc3.add(new StringField("id", "3", Field.Store.YES));
>> > doc3.add(new StringField("content", "Tom got a cat.",
>> > Field.Store.<http://field.store.no/>
>> > YES));
>> >  writer.addDocument(doc2);
>> > writer.addDocument(doc3);
>> >
>> >  writer.close();
>> >  System.out.println("------------ Added index -----------");
>> >  }
>> >
>> > }
>> >
>> >
>> >
>> > public class LuceneReader {
>> >
>> >
>> > /**
>> >
>> > * @param args
>> >
>> > */
>> >
>> > public static void main(String[] args) {
>> >
>> > try {
>> >
>> > IndexReader reader =
>> > DirectoryReader.open(FSDirectory.open(new File(DataConfig.dataDir)));
>> >
>> > IndexSearcher searcher =  new IndexSearcher(reader);
>> >
>> > HashMap<String, Analyzer> documentFieldAnalysers = new HashMap<String,
>> > Analyzer>();
>> >
>> > documentFieldAnalysers.put("id", new
>> StandardAnalyzer(Version.LUCENE_43));
>> >
>> > documentFieldAnalysers.put("content", new ShingleAnalyzerWrapper(new
>> > StandardAnalyzer(Version.LUCENE_43),
>> > 2, 2, "", false, true));
>> >
>> > PerFieldAnalyzerWrapper analyserWrapper
>> > = new PerFieldAnalyzerWrapper(new StandardAnalyzer(Version.LUCENE_43),
>> > documentFieldAnalysers);
>> >
>> > QueryParser qpHelper = new QueryParser(Version.LUCENE_43, "content",
>> > analyserWrapper);
>> >
>> > Query query = qpHelper.parse("amleagend");
>> >
>> > TopDocs results = searcher.search(query, 1000);
>> >
>> > System.out.println("Searching for: " + query);
>> >
>> > ScoreDoc[] hits = results.scoreDocs;
>> >
>> >
>> >
>> > for(int i =0; i < hits.length; i++)
>> >
>> > {
>> >
>> >   Document doc = searcher.doc(hits[i].doc);
>> >
>> >   System.out.println(doc);
>> >
>> > }
>> >
>> >
>> >
>> >
>> >
>> > } catch (Exception e) {
>> >
>> > // TODO Auto-generated catch block
>> >
>> > e.printStackTrace();
>> >
>> > }
>> >
>> >
>> > }
>> >
>> >
>> >
>> >
>> > }
>> >
>> >
>> > Thanks,
>> >
>> > Depanker Sharma
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message