我已经在我的应用中实现了搜索模块。该搜索不会搜索确切的短语,而是分别搜索该短语中的每个单词。例如,如果您搜索“ Comprehensive Metabolic”,则只希望看到CMP面板,但是搜索实际上返回的每个面板都有单词“ Comprehensive”或“ Metabolic”,这是一个更长的列表。 我可以获得任何帮助吗?
我可以使用任何管道来过滤精确搜索吗?
这是我的搜索组件html
if(myCart != default(ShoppingCart)){
// do stuff
}
其Ts文件
import json
import pickle
import numpy as np
import boto3
s3 = boto3.resource('s3')
# Function for transferring pickles from s3 to lambda
def download_files_from_s3():
with open('/tmp/km_model_on_space_data.pkl', 'wb') as f:
s3.Bucket("ml-model-first-try").download_fileobj("km_model_on_space_data.pkl", f)
with open('/tmp/tfidf_vectorizer.pkl', 'wb') as f:
s3.Bucket("ml-model-first-try").download_fileobj("tfidf_vectorizer.pkl", f)
with open('/tmp/cluster_distances.pkl', 'wb') as f:
s3.Bucket("ml-model-first-try").download_fileobj("cluster_distances.pkl", f)
with open('/tmp/space_ids_only.pkl', 'wb') as f:
s3.Bucket("ml-model-first-try").download_fileobj("space_ids_only.pkl", f)
# Downloading files from s3 to lambda ------------ Comment the next line if data is already downloaded
download_files_from_s3()
# Loading pickles
km = pickle.load(open('/tmp/km_model_on_space_data.pkl','rb'))
tfidf_vectorizer = pickle.load(open('/tmp/tfidf_vectorizer.pkl','rb'))
cluster_distances = pickle.load(open('/tmp/cluster_distances.pkl','rb'))
space_ids = pickle.load(open('/tmp/space_ids_only.pkl','rb'))
# Automatically called everytime
def lambda_handler(event, context):
tfidf = tfidf_vectorizer.transform([event['text']])
cluster = km.predict(tfidf)
cluster_arr = cluster_distances[:,cluster[0]]
cluter_arr_sorted = cluster_arr.argsort()
recommended_space_ids = []
for i in cluter_arr_sorted[0:10]:
recommended_space_ids.append(space_ids[i])
return {'Cluster_Number' : cluster[0], 'Space_Ids' : recommended_space_ids}
我将此添加到了我正在使用的组件中
此处是父组件的html
<input #searchInput type="text" (focus)="onFocus($event)" (blur)="onBlur($event)" (keyup)="onKeyUp($event)" placeholder="Search">
其Ts文件
@Input() searchTerm: string = "";
@Output() onSearchInputUpdate = new EventEmitter();
@ViewChild("searchInput") searchInputField: ElementRef;
public searchFocus: boolean;
private searchTermTimeoutId;
private waitTime: number = 500; // half a second
onBlur(event) {
// setTimeout so clearSearch click event has time to be called first
setTimeout(() => {
if (event.srcElement.value.length === 0) {
this.searchFocus = false;
}
}, 100);
}
onKeyUp(event) {
if (this.searchTermTimeoutId) {
clearTimeout(this.searchTermTimeoutId);
}
this.searchTermTimeoutId = setTimeout(() => {
this.onSearchInputUpdate.emit(this.searchInputField.nativeElement.value);
}, this.waitTime);
}