emersonbottero / vitepress-plugin-search

Provide local search to your documentation site.
MIT License
238 stars 30 forks source link

Is it possible to add config option for separator #71

Open JakeHalfpenny opened 1 year ago

JakeHalfpenny commented 1 year ago

If a project is setup to use spaces instead of - this would allow it to use search as it currently can't

example code below Search.vue

const separator = ref("-");

interface Options {
  previewLength: number;
  buttonLabel: string;
  placeholder: string;
  separator: string
}

const result = computed(() => {
  if (searchTerm.value) {
    var searchResults = searchIndex.value.search(searchTerm.value, { enrich: true })

    var search = [] as any[];

    for (var i = 0; i < searchResults.length; i++) {
      var id = searchResults[i];
      var item = PREVIEW_LOOKUP.value[id];

      var title = item["t"];
      var preview = item["p"];
      var link = item["l"];
      var anchor = item["a"];
      link = link.split(" ").join(Options.value?.separator);
      search.push({id: i, link, title, preview, anchor });
emersonbottero commented 1 year ago

check https://github.com/nextapps-de/flexsearch#charset-options