Hi, I am using Lucene v5.5.0
We are indexing a document into Lucene v5.5 using following code and trying to search for the document with a given Long value but the search does not yield any results. 1. This is how we are creating a document using Lucene v5.5 /** * Makes a Lucene document for an Asset. * <p> * The document has two fields: * <ul> * <li><code>AssetId</code>--Id of asset, as a stored, untokenized * field; and * <li><code>reader</code>--Reader for asset's text content to be indexed; */ public static Document createDocumentFromFile(long assetId, Reader reader) throws java.io.FileNotFoundException { // make a new, empty document Document doc = new Document(); // Add assetId as a field named "AssetId". AssetId will be indexed and stored // but does not need to be tokenised as it will be string representation // of number hence without any whitechars. doc.add(new LongField("AssetId", assetId, Field.Store.YES)); // Add the contents to a field named "TextContent". Specify a // Reader, so that the text of the file is tokenized and indexed, but not // stored. doc.add(new TextField("TextContent", reader)); // return the document return doc; } 2. Adding a document.... /* * Adds a Lucene Document to the index */ protected void addDocument(Document doc) throws IOException { indexWriter.addDocument(doc); commit(); } private void commit() throws IOException { indexWriter.commit(); long start = System.nanoTime(); //searcherManager.maybeRefresh(); searcherManager.maybeRefreshBlocking(); long end = System.nanoTime(); logger.trace("IndexReader reopen in (us): " + (end-start)/1000 ); } 3. Searching for a document...... for instance search for document with AssetId = 12 /* * Returns Lucene document corresponding to the given AssetId */ private Document getAssetDocument(long assetId) { final Document[] assetDoc = new Document[1]; try { /* * Query to find a lucene document based on AssetId field */ QueryParser assetIdQueryparser = new QueryParser("AssetId", standardAnalyzer); Query query = assetIdQueryparser.parse("" + assetId); query(query,Integer.MAX_VALUE, new TextQueryResultCollector() { @Override public void collect(TopDocs searchResult, IndexSearcher searcher) throws IOException { ScoreDoc[] s = searchResult.scoreDocs; if (s != null && s.length > 0) { assetDoc[0] = searcher.doc(searchResult.scoreDocs[0].doc); } } }); } catch (Exception e) { logger.error("Error Searching text index on field AssetId", e); } return assetDoc[0]; } protected void query(Query query, int maxResults, TextQueryResultCollector collector ) throws IOException { IndexSearcher searcher = null; try { searcher = searcherManager.acquire(); //Represents hits returned by indexSearcher.search(Query,int) TopDocs topDocs = searcher.search(query, maxResults); collector.collect(topDocs, searcher); } finally { try { searcherManager.release(searcher); } catch (IOException e) { logger.error("Error querying Text index." , e); } } } Can you please help in figuring out why searching a org.apache.lucene.document.LongField (with Lucene v5.5) using the org.apache.lucene.queryparser.classic.QueryParser does not yield results whereas a similar query parser when used for searching a TextField yields results ? Are LongField(s) indexed in a different manner ? Can you please help why the search does not yield results in Lucene v5.5 ? Thanks, Jaspreet Kaur