<commit_before>import Fuse from 'fuse.js';

export default function filterResults(query) {
  const searchUrl = queryInUrl(query);

  // TODO: Still need to do a strict match for url
  //  Should: Do a filter over strict url maatches
  //  THEN: they should jump to the top of the results,
  //      wrt to their same rankings relative rank to each
  //      other in the original Fuse search.
  //          -> Loop thru the fuse results,
  //              no loops needed, just filter both arrays,
  //              join them (filteredFuse first),
  const options = {
    shouldSort: true,
    // includeMatches: false,
    threshold: 0.7,
    maxPatternLength: 32,
    minMatchCharLength: 1,
    keys: ['title'],
  };
  const fuse = array => new Fuse(array, options);
  return tabArray => fuse(tabArray).search(query);
}

function queryInUrl(query) {
  return ({ url }) => url.toLowerCase().includes(query);
}<commit_msg>Tweak search threshold to be lower and handle url matches<commit_after>import Fuse from 'fuse.js';

export default function filterResults(query) {
  const searchUrl = queryInUrl(query);
  const options = {
    shouldSort: true,
    // includeMatches: false,
    threshold: 0.5,
    maxPatternLength: 32,
    minMatchCharLength: 1,
    keys: ['title'],
  };
  const fuse = array => new Fuse(array, options);
  return (tabArray) => {
    const fuseResults = fuse(tabArray).search(query);
    const urlResults = tabArray.filter(searchUrl);
    const headUrlMatches = fuseResults.filter(tab => urlResults.includes(tab));
    const tailUrlMatches = urlResults.filter(tab => !fuseResults.includes(tab));
    const tailMatches = fuseResults.filter(tab => !headUrlMatches.includes(tab));
    return [
      ...headUrlMatches,
      ...tailUrlMatches,
      ...tailMatches,
    ];
  };
}

function queryInUrl(query) {
  return ({ url }) => url.toLowerCase().includes(query);
}
{'fraction_non_alphanumeric': 0.12016940179989412, 'fraction_numerical': 0.005293806246691371, 'mean_word_length': 3.172185430463576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3983923', 'n_tokens_mistral': 580, 'n_tokens_neox': 560, 'n_words': 167}