<commit_before>/* See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Esri Inc. licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
load("classpath:search/js/WriterBase.js");

G.writers.atom = {
  
  writeItem: function(appRequest,appResponse,itemId,itemString,responseString) {
    var now = G.nowAsString();
    var options = {now:now,entryOnly:true};
    var xmlBuilder = G.newXmlBuilder();
    xmlBuilder.writeStartDocument();
    this._writeEntry(appRequest,itemId,itemString,xmlBuilder,options);
    xmlBuilder.writeEndDocument();
    this._writeAppResponse(appRequest,appResponse,xmlBuilder);
  },
  
  writeItems: function(searchRequest,appResponse,searchResponse) {
    var searchHits = searchResponse.getHits();
    var now = G.nowAsString();
    var options = {now:now, entryOnly:false};
    var xmlBuilder = G.newXmlBuilder();
    xmlBuilder.writeStartDocument();
    
    var hits = searchHits.getHits();
    var numReturned = hits.length;
    var totalHits = searchHits.getTotalHits();
    var from = searchRequest.getFrom();
    var size = searchRequest.getSize();
    
    var baseUrl = searchRequest.getBaseUrl();
    var dscUrl = baseUrl+"/Eros/description"; // TODO
    var feedId = baseUrl;
    var feedTitle = "Results"; // TODO - "Results"
    var authorName = baseUrl;
    
    xmlBuilder.writer.writeStartElement("atom","feed",G.URI_ATOM);
    this._addNamespaces(xmlBuilder);
    xmlBuilder.writeElement(G.URI_ATOM,"title",feedTitle);
    xmlBuilder.writeElement(G.URI_ATOM,"id",feedId); 
    xmlBuilder.writeElement(G.URI_ATOM,"updated",now); 
    xmlBuilder.writer.writeStartElement(G.URI_ATOM,"author");
    xmlBuilder.writeElement(G.URI_ATOM,"name",authorName);
    xmlBuilder.writer.writeEndElement();
    
    this._addLink("search","application/opensearchdescription+xml",dscUrl,xmlBuilder);
    xmlBuilder.writeElement(G.URI_OPENSEARCH,"totalResults",""+totalHits);
    xmlBuilder.writeElement(G.URI_OPENSEARCH,"startIndex",""+from); // TODO startIndex??
    xmlBuilder.writeElement(G.URI_OPENSEARCH,"itemsPerPage",""+size);
    
    this._addQuery(searchRequest,xmlBuilder);
    
    var i,hit;<commit_msg>Navigation links (first,last,next,prev,self) in Eros response.<commit_after>/* See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Esri Inc. licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
load("classpath:search/js/WriterBase.js");

G.writers.atom = {
  
  writeItem: function(appRequest,appResponse,itemId,itemString,responseString) {
    var now = G.nowAsString();
    var options = {now:now,entryOnly:true};
    var xmlBuilder = G.newXmlBuilder();
    xmlBuilder.writeStartDocument();
    this._writeEntry(appRequest,itemId,itemString,xmlBuilder,options);
    xmlBuilder.writeEndDocument();
    this._writeAppResponse(appRequest,appResponse,xmlBuilder);
  },
  
  writeItems: function(searchRequest,appResponse,searchResponse) {
    var searchHits = searchResponse.getHits();
    var now = G.nowAsString();
    var options = {now:now, entryOnly:false};
    var xmlBuilder = G.newXmlBuilder();
    xmlBuilder.writeStartDocument();
    
    var hits = searchHits.getHits();
    var numReturned = hits.length;
    var totalHits = searchHits.getTotalHits();
    var from = searchRequest.getFrom();
    var size = searchRequest.getSize();
    
    var baseUrl = searchRequest.getBaseUrl();
    var dscUrl = baseUrl+"/Eros/description"; // TODO
    var feedId = baseUrl;
    var feedTitle = "Results"; // TODO - "Results"
    var authorName = baseUrl;
    
    xmlBuilder.writer.writeStartElement("atom","feed",G.URI_ATOM);
    this._addNamespaces(xmlBuilder);
    xmlBuilder.writeElement(G.URI_ATOM,"title",feedTitle);
    xmlBuilder.writeElement(G.URI_ATOM,"id",feedId); 
    xmlBuilder.writeElement(G.URI_ATOM,"updated",now); 
    xmlBuilder.writer.writeStartElement(G.URI_ATOM,"author");
    xmlBuilder.writeElement(G.URI_ATOM,"name",authorName);
    xmlBuilder.writer.writeEndElement();
    
    this._addLink("search","application/opensearchdescription+xml",dscUrl,xmlBuilder);
    this._addLink("self","application/opensearchdescription+xml",baseUrl+"/Eros?from="+from+"&size="+size+(searchRequest.getPretty()?"&pretty=true":""),xmlBuilder);
    this._addLink("first","application/opensearchdescription+xml",baseUrl+"/Eros?from="+1+"&size="+size+(searchRequest.getPretty()?"&pretty=true":""),xmlBuilder);
    this._addLink("last","application/opensearchdescription+xml",baseUrl+"/Eros?from="+(size*Math.floor(totalHits/size))+"&size="+size+(searchRequest.getPretty()?"&pretty=true":""),xmlBuilder);
    if (from-size>=1) {
      this._addLink("prev","application/opensearchdescription+xml",baseUrl+"/Eros?from="+(from-size)+"&size="+size+(searchRequest.getPretty()?"&pretty=true":""),xmlBuilder);
    }
    if (from+size<=totalHits) {
      this._addLink("next","application/opensearchdescription+xml",baseUrl+"/Eros?from="+(from+size)+"&size="+size+(searchRequest.getPretty()?"&pretty=true":""),xmlBuilder);
    }
    
    xmlBuilder.writeElement(G.URI_OPENSEARCH,"totalResults",""+totalHits);
    xmlBuilder.writeElement(G.URI_OPENSEARCH,"startIndex",""+from); // TODO startIndex??
    xmlBuilder.writeElement(G.URI_OPENSEARCH,"itemsPerPage",""+size);
    
    this._addQuery(searchRequest,xmlBuilder);
    
    var i,hit;
{'fraction_non_alphanumeric': 0.1342866024246192, 'fraction_numerical': 0.001554243083618278, 'mean_word_length': 4.919963201471941, 'pattern_counts': {'":': 5, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 52}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6076721', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1908, 'n_words': 377}