lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Svensson <si...@devhost.se>
Subject Re: Need help in alphanumeric search
Date Mon, 28 Sep 2015 09:09:41 GMT
Hi,

You've sent the question to the Lucene.NET mailing list. Lucene.NET is a
.NET port of Lucene. It looks like you're using the original Java
version; you should probably redirect your question to any of their
channels.

https://lucene.apache.org/core/discussion.html

Anyhow, check what query is generated by QueryParser.parse and check if
there's any parts present for your numbers. They may be filtered out by
an analyzer.

// Simon

On 25/09/15 19:47, Bhaskar wrote:
> Hi,
> I am beginner in Apache lucene, I am using 5.3.1.
> I have created  the index on the database result. The index values are
> having alphanumeric and strings values. I am able to search the strings but
> I am not able to search alphanumeric values.
> 
> Can someone help me here.
> 
> Below is indexing code...
> 
> int indexDocs(IndexWriter writer, Connection conn) throws Exception {
> Statement stmt = conn.createStatement();
>   ResultSet rs = stmt.executeQuery(sql);
>   int i=0;
>   while (rs.next()) {
>      Document d = new Document();
>     // System.out.println("cpn is" + rs.getString("cpn"));
>     // System.out.println("mpn is" + rs.getString("mpn"));
> 
>   d.add(new TextField("cpn", rs.getString("cpn"), Field.Store.YES));
> 
> 
>      writer.addDocument(d);
>      i++;
>  }
> }
> 
> Searching code:
> 
> 
> private void searchIndex(Path indexDir, String queryStr) throws Exception {
> Directory directory = FSDirectory.open(indexDir);
> System.out.println("The query string is " + queryStr);
> // MultiFieldQueryParser queryParser = new MultiFieldQueryParser(new
> // String[] {"mpn"}, new StandardAnalyzer());
> // IndexReader reader = IndexReader.open(directory);
> IndexReader reader = DirectoryReader.open(directory);
> IndexSearcher searcher = new IndexSearcher(reader);
> Analyzer analyzer = new StandardAnalyzer();
> analyzer.tokenStream("cpn", queryStr);
> QueryParser parser = new QueryParser("cpn", analyzer);
> parser.setDefaultOperator(Operator.OR);
> parser.getAllowLeadingWildcard();
> parser.setAutoGeneratePhraseQueries(true);
> Query query = parser.parse(queryStr);
> searcher.search(query, 100);
> TopDocs topDocs = searcher.search(query, MAX_HITS);
> 
> ScoreDoc[] hits = topDocs.scoreDocs;
> System.out.println(hits.length + " Record(s) Found");
> for (int i = 0; i < hits.length; i++) {
> int docId = hits[i].doc;
> Document d = searcher.doc(docId);
> System.out.println("\"value is:\" " + d.get("cpn"));
> }
> if (hits.length == 0) {
> System.out.println("No Data Founds ");
> }
> 
> 
> Thanks in advance.
> 
> 


Mime
View raw message