Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
|
9920fc5ddd | ||
|
a8bbb9f303 | ||
|
6022d867a3 | ||
|
9b22c32322 | ||
|
a40259af30 | ||
|
87d2e9474c | ||
|
3137068c77 | ||
|
e79f1ce10b | ||
|
c52faeaddc | ||
|
a93fbe9d66 |
2 changed files with 12 additions and 1 deletions
|
@ -7,6 +7,7 @@ from pathlib import Path
|
|||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
|
||||
from mwmbl import background
|
||||
from mwmbl.crawler import app as crawler
|
||||
|
@ -65,6 +66,16 @@ def run():
|
|||
# Initialize FastApi instance
|
||||
app = FastAPI()
|
||||
|
||||
origins = ["*"]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
search_router = search.create_router(ranker)
|
||||
app.include_router(search_router)
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ class Ranker:
|
|||
def complete(self, q: str):
|
||||
ordered_results, terms, completions = self.get_results(q)
|
||||
filtered_completions = [c for c in completions if c != terms[-1]]
|
||||
urls = [item.url[len(HTTPS_STRING):].rstrip('/') for item in ordered_results[:5]
|
||||
urls = [item.url[len(HTTPS_STRING):].rstrip('/').replace('.', '․').replace('/', ' ∕ ') for item in ordered_results[:5]
|
||||
if item.url.startswith(HTTPS_STRING) and all(term in item.url for term in terms)][:1]
|
||||
completed = [' '.join(terms[:-1] + [t]) for t in filtered_completions]
|
||||
return [q, urls + completed]
|
||||
|
|
Loading…
Reference in a new issue