Personal tools
You are here: Home Leocornus leocornus.tracclient Batch indexing all tickets on Solr instance.

Batch indexing all tickets on Solr instance.

this is more like a sample to demonstrate how to import all tickets information and comments into a Solr instance.

Solr Data Import Configuration

Check the following configuration sample

<dataConfig>
  <dataSource type="JdbcDataSource"
              driver="org.sqlite.JDBC"
              url="jdbc:sqlite:/path/to/trac/db/trac.db" />
  <script><![CDATA[
  // parse the post content and extract the description for a post.
  function processTicket(row) {

      //Grab ticket description
      description = new String(row.get('description').trim());
      //create new string type object
      description_excerpt = new String();

      //if description length is more than 255 characters
      // substing it
      if( description.length > 255 ) {
          description_excerpt = description.substring(0, 255);
      } else {
          description_excerpt = description;
      }
      row.put('description_excerpt', description_excerpt);

      //Grab owner and reporter
      owner = new String(row.get('owner'));
      reporter = new String(row.get('reporter'));
      //create new string type object
      authors = new String();
      if(owner.equals(reporter))
          row.put('authors', owner);
      else
          row.put('authors', owner+','+reporter);\

      // set the site to Trac Tickets.
      row.put('site', 'Trac Tickets');
      return row;
  }
  ]]></script>

  <document>
    <entity name="ticket"
            query="select
                   id,
                   summary,
                   description,
                   strftime('%Y-%m-%dT%H:%M:%S%fZ',
                   changetime/1000000,'unixepoch') as changetime,
                   strftime('%Y-%m-%dT%H:%M:%S%fZ',
                   time/1000000,'unixepoch') as time,
                   owner,
                   reporter,
                   keywords,
                   component,
                   priority,
                   type,
                   version,
                   milestone,
                   status,
                   resolution
                   from ticket"
            transformer="script:processTicket,TemplateTransformer,RegexTransformer"
            processor="SqlEntityProcessor">

      <field column="id" name="id" />
      <field column="summary" name="title" />
      <field column="description_excerpt" name="description" />
      <field column="description" name="content" />
      <field column="changetime" name="lastModifiedDate" />
      <field column="url" name="url"
          template="http://url.to.trac.com/trac/ticket/?id=${ticket.id}"/>
      <field column="site" name="site" />
      <field column="authors" splitBy="," name="authors" />
      <field column="keywords" splitBy="," name="keywords" />
      <field column="component" name="keywords" />
      <field column="priority" name="keywords" />
      <field column="type" name="keywords" />
      <field column="version" name="keywords" />
      <field column="milestone" name="keywords" />
      <field column="status" name="keywords" />
      <field column="resolution" name="keywords" />
      <field column="time" name="creationDate" />

      <!--
      <entity name="comments"
            query="select newvalue from ticket_change where field ='comment' and ticket = ${ticket.id}"
            processor="SqlEntityProcessor"
            transformer="TemplateTransformer">
        <field column="newvalue" name="comments" />
      </entity>
      -->
    </entity>

  </document>
</dataConfig>

Tracking History

When Who What Done
2013-10-08 06:07 Sean Chen The solr data importer handler works fine.
-- 3.0 Hours, 100.0% Done
Document Actions