<p>I use solr to search for documents and when trying to search for documents using this query "<code>id:*</code>", I get this query parser exception telling that it cannot parse the query with * or ? as the first character. </p>

<pre><code>HTTP Status 400 - org.apache.lucene.queryParser.ParseException: Cannot parse 'id:*': '*' or '?' not allowed as first character in WildcardQuery

type Status report

message org.apache.lucene.queryParser.ParseException: Cannot parse 'id:*': '*' or '?' not allowed as first character in WildcardQuery

description The request sent by the client was syntactically incorrect (org.apache.lucene.queryParser.ParseException: Cannot parse 'id:*': '*' or '?' not allowed as first character in WildcardQuery).
</code></pre>

<p>Is there any patch for getting this to work with just * ? Or is it very costly to do such a query?</p>

[{'answer_id': 16661, 'author': 'Ryan Ahearn', 'author_id': 75, 'author_profile': 'https://Stackoverflow.com/users/75', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m assuming with id:* you\'re just trying to match all documents, right?</p>\n\n<p>I\'ve never used solr before, but in my Lucene experience, when ingesting data, we\'ve added a hidden field to every document, then when we need to return every record we do a search for the string constant in that field that\'s the same for every record.</p>\n\n<p>If you can\'t add a field like that in your situation, you could use a RegexQuery with a regex that would match anything that could be found in the id field.</p>\n\n<p>Edit: actually answering the question.  I\'ve never heard of a patch to get that to work, but I would be surprised if it could even be made to work reasonably well.  See <a href="https://stackoverflow.com/questions/8532/with-lucene-why-do-i-get-a-too-many-clauses-error-if-i-do-a-prefix-search">this question</a> for a reason why unconstrained PrefixQuery\'s can cause a problem.</p>\n'}, {'answer_id': 17458, 'author': 'cnu', 'author_id': 1448, 'author_profile': 'https://Stackoverflow.com/users/1448', 'pm_score': 1, 'selected': False, 'text': '<p>Actually, I have been using a workaround for this. I append a character to the id, eg: A1, A2, etc.</p>\n\n<p>With such values in the field, it is possible to search using the query <code>id:A*</code></p>\n\n<p>But would love to find whether a true solution exists.</p>\n'}, {'answer_id': 23095, 'author': 'Joe Shaw', 'author_id': 156, 'author_profile': 'https://Stackoverflow.com/users/156', 'pm_score': 3, 'selected': False, 'text': "<p>Lucene doesn't allow you to start WildcardQueries with an asterisk by default, because those are incredibly expensive queries and will be very, very, very slow on large indexes.</p>\n\n<p>If you're using the Lucene QueryParser, call setAllowLeadingWildcard(true) on it to enable it.</p>\n\n<p>If you want all of the documents with a certain field set, you are much better off querying or walking the index programmatically than using QueryParser.  You should really only use QueryParser to parse user input.</p>\n"}, {'answer_id': 23554, 'author': 'dlamblin', 'author_id': 459, 'author_profile': 'https://Stackoverflow.com/users/459', 'pm_score': 3, 'selected': False, 'text': '<pre><code>id:[a* TO z*] id:[0* TO 9*] etc.\n</code></pre>\n\n<p>I just did this in lukeall on my index and it worked, therefore it should work in Solr which uses the standard query parser. I don\'t actually use Solr.</p>\n\n<p>In base Lucene there\'s a fine reason for why you\'d never query for every document, it\'s because to query for a document you must use a <code>new indexReader("DirectoryName")</code> and apply a query to it. Therefore you could totally skip applying a query to it and use the <code>indexReader</code> methods <code>numDocs()</code> to get a count of all the documents, and <code>document(int n)</code> to retrieve any of the documents.</p>\n'}, {'answer_id': 74475, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 4, 'selected': False, 'text': '<p>If you want all documents, do a query on &#042;:&#042;</p>\n\n<p>If you want all documents with a certain field (e.g. id) try id:[* TO *]</p>\n'}, {'answer_id': 104416, 'author': 'Mark B', 'author_id': 13070, 'author_profile': 'https://Stackoverflow.com/users/13070', 'pm_score': 2, 'selected': False, 'text': '<p>If you are just trying to get all documents, Solr does support the *:* query.  It\'s the only time I know of that Solr will let you begin a query with an *.  I\'m sure you\'ve probably seen this as the default query in the Solr admin page.</p>\n\n<p>If you are trying to do a more specific query with an * as the first character, like say id:*456 then one of the best ways I\'ve seen is to index that field twice.  Once normally (field name: id), and once with all the characters reversed (field name: reverse_id).  Then you could essentially do the query id:<em>456 by sending the query reverse_id:654</em> instead.  Hope that makes sense.</p>\n\n<p>You can also search the Solr user group mailing list at <a href="http://www.mail-archive.com/solr-user@lucene.apache.org/" rel="nofollow noreferrer">http://www.mail-archive.com/solr-user@lucene.apache.org/</a> where questions like this come up quite often.</p>\n'}, {'answer_id': 6899858, 'author': 'Daniel Rijkhof', 'author_id': 648458, 'author_profile': 'https://Stackoverflow.com/users/648458', 'pm_score': 2, 'selected': False, 'text': '<p>The following Solr issue is a request to be able to configure the default lucene query parser.\n<a href="https://issues.apache.org/jira/browse/SOLR-218" rel="nofollow">https://issues.apache.org/jira/browse/SOLR-218</a></p>\n\n<p>In this issue you can find the following description how to \'patch\' Solr. This modification would allow you to start queries with a *.</p>\n\n<blockquote>\n  <p>Jonas Salk: I\'ve basically updated only one Java file: SolrQueryParser.java.</p>\n</blockquote>\n\n<pre><code>public SolrQueryParser(IndexSchema schema, String defaultField) { \n    ... \n    setAllowLeadingWildcard(true); \n    setLowercaseExpandedTerms(true); \n    ... \n}\n\n ...\n\npublic SolrQueryParser(QParser parser, String defaultField, Analyzer analyzer) {\n    ... \n    setAllowLeadingWildcard(true); \n    setLowercaseExpandedTerms(true);\n    ... \n}\n</code></pre>\n\n<p>I\'m not sure if setLowercaseExpandedTerms is needed...</p>\n'}]
['https://Stackoverflow.com/questions/15979', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1448/']