def match_by_title(self,item): """ Bir merchant item'in title bilgilerine dayanarak solr matchleri arar @type item: L{cimri.api.cimriservice.data.merchantitem.MerchantItem} @param item: arama bilgilerini iceren MerchantItem @rtype: list @return: Solr query sonuclari ya da hata durumunda None """ self.logger.info("solr call...") #construct query query=Template("merchantItemTitle:\"$title\"").substitute(title=SolrAPI.escape(item.merchantItemTitle)) #make query items=self.call(query) #anything found? if len(items)==0: return None elif len(items)==1: return items[0] else: #if all the matched items point to the same catalog item, item is matched if len(set([item['itemId'] for item in items]))==1: return items[0] return None
def match_by_title_keywords(self,title): """ Title icide yer alabilecek keywordlere gore solr matchleri arar @type title: str @param title: aranacak keywordleri iceren title @rtype: list @return: Solr query sonuclari ya da hata durumunda None """ self.logger.info("solr call...") #get keywords tokens=title.split(" ") keywords=[SolrAPI.escape(token.strip()) for token in tokens if token.strip()!=""] #construct query #query=Template("merchantItemTitle:(${keywords})").substitute(keywords=" ".join(keywords)) query=Template("merchantItemTitle2:(${keywords})").substitute(keywords=" ".join(keywords)) #make query items=self.call(query) #return the top N matches return items[:20]
def match_by_title_keywords(self,title): """ Title icide yer alabilecek keywordlere gore solr matchleri arar @type title: str @param title: aranacak keywordleri iceren title @rtype: L{twisted.internet.defer.Deferred} @return: hata ya da sonuclari kabul edicek bir Deferred objecti """ self.logger.info("solr call...") #get keywords tokens=title.split(" ") keywords=[SolrAPI.escape(token.strip()) for token in tokens if token.strip()!=""] #any keywords? if len(keywords)==0: res=Deferred() res.callback([]) return res #construct query query=Template("merchantItemTitle2:(${keywords})").substitute(keywords=" ".join(keywords)) #make query res=self.call(query) return res
def match_by_ids(self,ids): """ Bir itemid listesine dayanarak solr matchleri arar @type ids: list @param ids: aranan item Idleri iceren liste @rtype: list @return: Solr query sonuclari ya da hata durumunda None """ self.logger.info("solr call...") #any ids passed? if len(ids)==0: res=Deferred() res.callback([]) return res #construct query ids=" OR ".join([SolrAPI.escape(str(id)) for id in ids]) query=Template("id:(${ids})").substitute(ids=ids) #make query matches=self.call(query) #return results return matches
def match_by_mpn(self,keywords): """ Mpn bilgilerine dayanarak solr matchleri arar @type keywords: list @param keywords: aranan mpn icin keywordleri iceren liste @rtype: L{twisted.internet.defer.Deferred} @return: hata ya da sonuclari kabul edicek bir Deferred objecti """ self.logger.info("solr call...") #any keywords passed? if len(keywords)==0: res=Deferred() res.callback([]) return res #construct query query=Template("mpnValue:(${keywords})").substitute(keywords=SolrAPI.escape(" ".join(keywords))) #make query res=self.call(query) return res
def match_by_model(self,keywords): """ Model ismine dayanarak solr matchleri arar @type keywords: list @param keywords: aranan model icin keywordleri iceren liste @rtype: list @return: Solr query sonuclari ya da hata durumunda None """ self.logger.info("solr call...") #any keywords passed? if len(keywords)==0: return None #construct query query=Template("model:(${keywords})").substitute(keywords=SolrAPI.escape(" ".join(keywords))) #make query matches=self.call(query) #sort by score matches.sort(lambda a,b: int(100*(b["score"]-a["score"]))) #pick the top N return matches[:25]
def suggestions_by_title_and_brand(self,title,brand,mpn): """ Title, brand, ve mpn bilgilerine dayanarak solr matchleri arar @type title: str @param title: title bilgileri @type brand: str @param brand: brand bilgileri @type mpn: str @param mpn: mpn bilgileri @rtype: list @return: Solr query sonuclari ya da hata durumunda None """ self.logger.info("solr call...") #process keywrods and brand keywords=lower_non_turkish_alphanumeric(title).strip() brand=lower_non_turkish_alphanumeric(brand).strip() mpn=replace_turkish_chars(mpn).strip() #append mpn to keywords if mpn!="": keywords=keywords+" "+mpn #construct query query=Template("keywords:(${keywords})").substitute(keywords=SolrAPI.escape(keywords)) #add brand if not empty if brand!="": query=Template("$query brand:(${brand})").substitute(query=query,brand=SolrAPI.escape(brand)) #make query suggestions=self.call(query,rows=100) #return all suggestions return suggestions
def match_by_brands(self,title,brands=[]): """ Brand isimlerine ve title icindeki olasi brand keywordlerine dayanarak solr matchleri arar @type title: str @param title: aranacak keywordleri iceren title @type brands: list @param brands: aranacak brandleri iceren liste @rtype: list @return: Solr query sonuclari ya da hata durumunda None """ self.logger.info("solr call...") #any brands passed? if len(brands)==0: return None #query results matches=[] #run queries for brand in brands: #construct query query=Template("keywords:(+$brand $title)").substitute(brand=SolrAPI.escape(brand),title=SolrAPI.escape(title)) #make query items=self.call(query) #anthing matched? if len(items)>0: matches.append(items[0]) #anything matched? if len(matches)==0: return None #sort by socre matches.sort(lambda a,b: int(100*(b["score"]-a["score"]))) #if the best match is above the score threshold, we have a match if matches[0]["score"] > 3: return matches[0] return None