Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-1795

Subclassing QueryComponent for fetching results from a database

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 1.4
    • None
    • None

    Description

      This is a request to change the access on a few fields from package to public.

      I've subclassed QueryComponent to allow me to fetch results from a database (based upon the stored uniqueKey field) instead of from the shards. The only stored field in solr is the uniqueKey field, and whatever fields I might need for sorting. To do this I've overridden QueryComponent.finishStage so that after executing the query, SolrDocuments are created with the uniqueKey field. A later component populates the rest of the fields in the documents by reading them from a database.

      public void finishStage(ResponseBuilder rb) {
         if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
            // Create SolrDocument's from the ShardDoc's
            boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
            for (ShardDoc sdoc : rb.resultIds.values()) {
               SolrDocument doc = new SolrDocument();
               doc.setField("id", sdoc.id);
               if (returnScores && sdoc.score != null) {
                  doc.setField("score", sdoc.score);
               }
               rb._responseDocs.set(sdoc.positionInResponse, doc);
            }
         }
      }
      

      Everything works fine, but ResponseBuilder variables: resultIds and _responseDocs, and ShardDoc variables: id, score, and positionInResponse currently all have package visibility. I needed to modify the core solr files to change their visibility to public so that I could access them in the function above. Is there any chance that they could be changed to public in a future version of Solr, or somehow make them accessible outside the package?

      If people are interested, I could post the QueryComponent subclass and database component that I wrote. But it gets a bit involved because the QueryComponent subclass also handles parsing the query just at the main solr server, and sending serialized parsed queries to the shards. (Query parsing in my environment is pretty cpu- and memory-intensive so I do it just at the main server instead of the shards.)

      Attachments

        Activity

          People

            Unassigned Unassigned
            dallanq Dallan Quass
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: