I have an index and one of the items to search for is an identifier that will always be 3 characters, like ABC or XYZ. If I do a search for ABC I get no matches. If I add 1 more character so that ABC becomes ABCD and search for ABCD, it matches. I have been looking through the code (I inherited and the original coder is no longer with the company) to see if there is any place where he might have put a limitation in, but testing indicates that it is creating a query. Some code below:
QueryParser parser = new QueryParser(Version.LUCENE_34, TaskRecord.BaseFields.PUBLIC_DEFAULT_FIELD.getName(), getAnalyzer()); parser.setDefaultOperator(Operator.AND); Query query = parser.parse(qstring); qstring is the search text and getAnalyser returns a StandardAnalyzer. The Query is then used to search using the following code: public List<Long> search(Query query) throws IOException { IndexReader reader = null; try { reader = IndexReader.open(getRoot(), true); IndexSearcher searcher = new IndexSearcher(reader); // Do the search with an artificial limit of 32 results TopDocs hits = searcher.search(query, 32); // If the search actually has more hits, then run it again with correct max if(hits.totalHits > 32) { if(log.isDebugEnabled()) { log.debug("Rerunning query with max size of " + hits.totalHits + " " + query); } hits = searcher.search(query, hits.totalHits); } // Create task ID list and return if(hits.totalHits < 1) { if(log.isDebugEnabled()) log.debug("Query has no hits " + query); return Collections.emptyList(); } else { if(log.isDebugEnabled()) log.debug("Query has " + hits.totalHits + " hits " + query); List<Long> taskIds = new ArrayList<Long>(hits.totalHits); for(ScoreDoc doc: hits.scoreDocs) { taskIds.add(Long.valueOf(searcher.doc(doc.doc).get("task"))); } return taskIds; } } finally { try { if(reader != null) reader.close(); } catch(IOException e) { } } } > -----Original Message----- > From: Chris Hostetter [mailto:hossman_luc...@fucit.org] > Sent: Wednesday, September 26, 2012 5:18 PM > To: java-user@lucene.apache.org > Subject: Re: short search terms > > > : I have a key field that will only ever have a length of 3 characters. > I am > : using a StandardAnalyzer and a QueryParser to create the Query > : (parser.parse(string)), and an IndexReader and IndexSearcher to > execute the > : query (searcher(query)). I can't seem to find a setter to allow for a > 3 > : character search string. There is one setMinWordLen, but it isn't > applicable > > there's a lot of missing information here ... what do you mean "allow > for > a 3 character search string" .. the query parser doesn't have anything > in > it that would prevent a 3 (or 3, or 1) character search string, so i > suspect that's not really the question you mean to ask. > > what is problem you are actaully seeing? do you have a query that > isn't > matching the docs you think it should? what query? what docs? what does > the code look like? > > can you explain more what this 3 character ifeld represents, and how > you > want to use it? > > https://people.apache.org/~hossman/#xyproblem > Your question appears to be an "XY Problem" ... that is: you are > dealing > with "X", you are assuming "Y" will help you, and you are asking about > "Y" > without giving more details about the "X" so that we can understand the > full issue. Perhaps the best solution doesn't involve "Y" at all? > See Also: http://www.perlmonks.org/index.pl?node_id=542341 > > -Hoss > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org