如何在Solr中进行多字模糊搜索?

时间:2019-02-15 09:22:03

标签: search solr full-text-search

为了解释我的情况,我创建了一个要在solr搜索中复制的python脚本 在脚本中,我创建了字段的所有排列并通过排列对整个描述进行模糊搜索

import json
from itertools import permutations
from fuzzywuzzy import fuzz
from fuzzywuzzy import process


def search(description):
    with open('test.json') as jsonString:
        testDataList = json.load(jsonString)
    fuzzyOutputs = []
    for item in testDataList:      
        maxratio = 0
        dataPermutations = list(permutations([item["field1"], item["field2"], item["field3"], item["field4"]]))
        for combination in dataPermutations:    
           ratio = fuzz.partial_ratio(description, combination)
           if ratio > maxratio:
               maxratio = ratio
        if maxratio > 80: 
            fuzzyOutputs.append({
                "data": item,
                "fuzzyRatio": maxratio
            })

    print(fuzzyOutputs)
    return json.dumps({
        "fuzzyOutputs": fuzzyOutputs
    })

print(search("QUICK FOX JUMP OVER"))

我如何在solr中复制此代码?是否有预定义的方法?还是应该为此创建自定义过滤器?

0 个答案:

没有答案