title: solrj search on particular field
body: <p>I am using solrj to perform a query search from solr installation.</p>
  
  <p>This is what i have:</p>
  
  <pre><code>public List&lt;Details&gt; search(String query, int first, int rows) {
      List&lt;Details&gt; cds = new ArrayList&lt;Details&gt;();
      try {
        SolrQuery q = new SolrQuery();
        q.set("q", "name:" + query); //this throws an error on the solr side!
        q.setFields("id");
        q.setRows(rows);
        q.setStart(first);
        QueryResponse r = server.query(q);
        final SolrDocumentList docList = r.getResults();
        for (SolrDocument doc : docList) {
          String id_ = doc.getFieldValue("id").toString();
          Long id = Long.parseLong(id_);
          Details cd = detailsFacade.find(id);
          cds.add(cd);
        }
      } catch (SolrServerException ex) {
        Logger.getLogger(SolrIndexer.class.getName()).log(Level.SEVERE, null, ex);
      }
      return cds;
    }
  
    public int count(String query) {
      try {
        SolrQuery q = new SolrQuery();
        q.set("q", "name:" + query); //this throws an error on the solr side
        q.setRows(0);  // don't actually request any data
        return (int) server.query(q).getResults().getNumFound();
      } catch (SolrServerException ex) {
        Logger.getLogger(SolrIndexer.class.getName()).log(Level.SEVERE, null, ex);
      }
      return 0;
    }
  </code></pre>
  
  <p>I want to do a query on the name field only. (I have several fields with data for the indexed documents).</p>
  
  <p>The error on the solr side:</p>
  
  <pre><code>1126326 [qtp1645986986-17] ERROR org.apache.solr.core.SolrCore  – org.apache.solr.common.SolrException: org.apache.solr.search.SyntaxError: Cannot parse 'name:': Encountered "&lt;EOF&gt;" at line 1, column 5.
  Was expecting one of:
      &lt;BAREOPER&gt; ...
      "(" ...
      "*" ...
      &lt;QUOTED&gt; ...
      &lt;TERM&gt; ...
      &lt;PREFIXTERM&gt; ...
      &lt;WILDTERM&gt; ...
      &lt;REGEXPTERM&gt; ...
      "[" ...
      "{" ...
      &lt;LPARAMS&gt; ...
      &lt;NUMBER&gt; ...
  
      at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:171)
      at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:187)
      at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
      at org.apache.solr.core.SolrCore.execute(SolrCore.java:1859)
      at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:721)
      at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:417)
      at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:201)
      at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
      at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
      at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
      at org.eclipse.jetty.server.Server.handle(Server.java:368)
      at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
      at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
      at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
      at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
      at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
      at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
      at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
      at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
      at java.lang.Thread.run(Thread.java:724)
  Caused by: org.apache.solr.search.SyntaxError: Cannot parse 'name:': Encountered "&lt;EOF&gt;" at line 1, column 5.
  Was expecting one of:
      &lt;BAREOPER&gt; ...
      "(" ...
      "*" ...
      &lt;QUOTED&gt; ...
      &lt;TERM&gt; ...
      &lt;PREFIXTERM&gt; ...
      &lt;WILDTERM&gt; ...
      &lt;REGEXPTERM&gt; ...
      "[" ...
      "{" ...
      &lt;LPARAMS&gt; ...
      &lt;NUMBER&gt; ...
  
      at org.apache.solr.parser.SolrQueryParserBase.parse(SolrQueryParserBase.java:157)
      at org.apache.solr.search.LuceneQParser.parse(LuceneQParser.java:50)
      at org.apache.solr.search.QParser.getQuery(QParser.java:142)
      at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:142)
      ... 31 more
  Caused by: org.apache.solr.parser.ParseException: Encountered "&lt;EOF&gt;" at line 1, column 5.
  Was expecting one of:
      &lt;BAREOPER&gt; ...
      "(" ...
      "*" ...
      &lt;QUOTED&gt; ...
      &lt;TERM&gt; ...
      &lt;PREFIXTERM&gt; ...
      &lt;WILDTERM&gt; ...
      &lt;REGEXPTERM&gt; ...
      "[" ...
      "{" ...
      &lt;LPARAMS&gt; ...
      &lt;NUMBER&gt; ...
  
      at org.apache.solr.parser.QueryParser.generateParseException(QueryParser.java:651)
      at org.apache.solr.parser.QueryParser.jj_consume_token(QueryParser.java:533)
      at org.apache.solr.parser.QueryParser.Clause(QueryParser.java:217)
      at org.apache.solr.parser.QueryParser.Query(QueryParser.java:108)
      at org.apache.solr.parser.QueryParser.TopLevelQuery(QueryParser.java:97)
      at org.apache.solr.parser.SolrQueryParserBase.parse(SolrQueryParserBase.java:153)
      ... 34 more
  </code></pre>
  
  <p>How can i achieve this?</p>
  
  <p>Thanks</p>