<commit_before>var ChannelSearchResult = React.createClass({
  render: function() {
    var url = this.props.url ? this.props.url : "/channels/"+this.props.id+"#comments";
    var selected = "";
    if(this.props.selected) selected = "selected";
    return <li className={selected}><a href={url}>{this.props.title}</a></li>;
  }
});

function searchUrl(query) {
  return document.location.origin + "/search?utf8=✓&search="+encodeURIComponent(query);
}

var ChannelSearchResults = React.createClass({
  render: function() {
    var selection = this.props.cursor;
    var selectedDefault = selection == -1;
    var searchTitle = <span>Search for <em>{this.props.query}</em></span>;
    var defaultResult = null;
    if(this.props.query.length > 0)
      defaultResult = <ChannelSearchResult url={searchUrl(this.props.query)} selected={selectedDefault} title={searchTitle} />
    var showResult = function(result, index) {
      var selected = index == selection;
      if(!result.id) console.log(result);
      return <ChannelSearchResult id={result.id} key={result.id} title={result.title} selected={selected} />;
    };
    return <ul className='results'>
      {defaultResult}
      {this.props.results.map(showResult)}
    </ul>;
  }
});

var ChannelSearch = React.createClass({
  getInitialState: function() {
    return {hidden: true, query: '', cursor: -1, results: []};
  },
  handleSubmit: function(e) {
    e.preventDefault();
  },
  onChange: function(e) {
    var query = e.target.value;
    this.setState({query: query});
    if(query.length < 2) {
      this.setState({results: []});
      return;
    }
    var q = "";
    var seg = query.split(" ");
    for(var k in seg) {
      var t = seg[k];
      q += "title:"+t+" ";
    }
    var c = this;
    $.getJSON("/search", {"search": q, "per_page": 50}, function(data, status, xhr) {
      c.setState({results: data.objects});
    });<commit_msg>Only show results for most recent search query<commit_after>var ChannelSearchResult = React.createClass({
  render: function() {
    var url = this.props.url ? this.props.url : "/channels/"+this.props.id+"#comments";
    var selected = "";
    if(this.props.selected) selected = "selected";
    return <li className={selected}><a href={url}>{this.props.title}</a></li>;
  }
});

function searchUrl(query) {
  return document.location.origin + "/search?utf8=✓&search="+encodeURIComponent(query);
}

var ChannelSearchResults = React.createClass({
  render: function() {
    var selection = this.props.cursor;
    var selectedDefault = selection == -1;
    var searchTitle = <span>Search for <em>{this.props.query}</em></span>;
    var defaultResult = null;
    if(this.props.query.length > 0)
      defaultResult = <ChannelSearchResult url={searchUrl(this.props.query)} selected={selectedDefault} title={searchTitle} />
    var showResult = function(result, index) {
      var selected = index == selection;
      if(!result.id) console.log(result);
      return <ChannelSearchResult id={result.id} key={result.id} title={result.title} selected={selected} />;
    };
    return <ul className='results'>
      {defaultResult}
      {this.props.results.map(showResult)}
    </ul>;
  }
});

var ChannelSearch = React.createClass({
  getInitialState: function() {
    return {hidden: true, query: '', cursor: -1, results: [], n: -1};
  },
  handleSubmit: function(e) {
    e.preventDefault();
  },
  onChange: function(e) {
    var query = e.target.value;
    var n = this.state.n + 1;
    this.setState({query: query, n: n});
    if(query.length < 2) {
      this.setState({results: []});
      return;
    }
    var q = "";
    var seg = query.split(" ");
    for(var k in seg) {
      var t = seg[k];
      q += "title:"+t+" ";
    }
    var c = this;
    $.getJSON("/search", {"search": q, "per_page": 50}, function(data, status, xhr) {
      if(c.state.n != n) return;
      c.setState({results: data.objects});
    });
{'fraction_non_alphanumeric': 0.17443340972752738, 'fraction_numerical': 0.004074357015533486, 'mean_word_length': 3.388826815642458, 'pattern_counts': {'":': 4, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3007391', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1242, 'n_words': 270}