Wikipedia search box; database vs autocomplete

71 views Asked by At

I'd like to create a search box similar to the one Wikipedia uses. If you type in "lion," several terms containing lion are displayed, from lion to Lionel Messi. If you then hit the enter/return key, the first page is displayed by default. Or you can click on another term to display that page.

I found a jQuery script that looks like it should do the job at https://jqueryui.com/autocomplete/ I set it up on a local page, and the autocomplete function works, but I'm not sure what to do next.

The code I'm working with includes the following:

var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
];

So those are the terms that are displayed under autocomplete. I assume I just need to write a query and replace those terms with a list of page titles from my database. So here's my question:

I'm going to have thousands of pages in my database. Surely, I don't want to display every possible term by default. How can I set this up so it only displays terms related to the word a user types in? That would include titles that begin with "lion" as well as anything that includes the word "lion" (e.g. ant lion).

0

There are 0 answers