ä»æ¥ããã®çŽ æŽãããæ¥ã®æ¥ã«ããããªæ€çŽ¢ã ãã§ãªããæè¡çãªããšã«ã€ããŠãæžããããšæããŸãã
ããŒããããDjangoãããžã§ã¯ãã§ã®Sphinxsearchã®åäœã®å®è£
ã
ãããããããžãã¹ã¿ã¹ã¯ãèšå®ããããšããå§ãã䟡å€ããããŸãã
- ã¿ã€ãã«ã説æããã®ä»ã®ããã¹ãããŒã¿ã§é¢é£åç»ãæ€çŽ¢ããå¿ èŠããããŸã
- ååç»ã«ã€ããŠã é¢é£åç»ãæ¢ãå¿ èŠããããŸã
- é©åãªå Žæã§é©åãªãªã¯ãšã¹ããçºè¡ããéã«ã é©åãªãããªã衚瀺ããå¿ èŠããããŸãã
éæ©èœèŠä»¶ïŒ
- dofigãã¥ãŒãšãããªã®èª¬æã®ç¶ç¶çãªæŽæ°ãå«ãDjangoãããžã§ã¯ã
- ã©ã€ãã©ãªå ã®æ€çŽ¢ãšã³ãžã³ã§ã®äœæ¥ã®ã«ãã»ã«åãšããµã€ãäžã®ä»ã®ã©ã€ãã©ãªãšã®äºææ§ïŒãŸããDjango REST FrameworkïŒ
Rutubeã§sphinxsearchãã©ã®ããã«äœ¿çšãããŠãããããããŠãã®ã¹ããŒãªãŒã¯ã©ããªãã
ãããªã®é¢é£æ§ãšæ°åŠã«ã€ããŠ
ã€ã³ã¿ãŒãããã§ã®æ€çŽ¢ã«ã€ããŠè©±ãå Žåãéåžžã¯ããã¹ãæ
å ±ãæ€çŽ¢ããããšãæå³ããŸãã ãããªã®å Žåããã¹ãŠãã¯ããã«æªãã§ãã éåžžã人ãšã¯éåžžã«å
·äœçãªèŠèŠçã€ã¡ãŒãžãæå³ãããªã¯ãšã¹ãã®ããã¹ãã«å€æããŸãã ãµã€ãã«åç»ãã¢ããããŒãããŠããä»ã®äººã¯ãåç»ã®å
容ãåç»ã®ã¿ã€ãã«ãšèª¬æã«ç¿»èš³ããŸããããtestãããsdfsdfãããŸãã¯ã111ãã§ãªããã°è¯ãã§ãããã ãããã«ãããæå°éã®ããã¹ãæ
å ±ã®ã¿ãååšããç·šéã¹ã¿ãããšããŒãããŒãŠãŒã¶ãŒãæ·»ä»ããã¡ã¿ããŒã¿ããããŸãã ããªããæ€çŽ¢ããã°ã©ãã§ããå Žåãããªãæ€çŽ¢ãããªãã®ã§ããïŒRpïŒããšãã質åã¯å€ã«ããªããæ©ãŸããŸããç¹å¥ãªãã¹ããŠãŒãã£ãªãã£ã¯ããããã®è³ªåã«çããã®ã«åœ¹ç«ã¡ãŸãã
ããã¯ãæ€çŽ¢ã¯ãšãªã«ãã£ãŠãã€ã³ããã¯ã¹ã«ãããã¹ãŠã®ãã£ãŒã«ããæã€ãããªã ãã§ãªããåããã¥ã¡ã³ãã®ãã¹ãŠã®ç¹æ§ã®å€ãæã€ã©ã³ã«ãŒããã®æ
å ±ãè¿ãããŒãžã§ãã ãã®ããã«ã PACKEDFACTORS()
ã SNIPPETS()
ããã³CALL KEYWORDS
èŠæ±ãããŸãã éåžžããã®ããŒãžã®ããŒã¿ã¯ã ç¡é¢ä¿ãšåŒã°ãããã®ãæ°åŠçã«å®èšŒããã®ã«ååã§ãïŒããã§ã¯ãããã°ã©ãã ããæ°åŠçãªæå³ã§ç解ããæ®ãã¯ãã¹ãŠéçãªæå³ã§ç解ã§ããéæ³ã®èšèã§ãïŒïŒ...äžèšã®é¢é£ ã
Djangoããã¯ãšã³ãæ€çŽ¢ããŒã¹
Sphinxsearchã¯mysqlã¯ã©ã€ã¢ã³ãããµããŒãããŠããã®ã§ãDjangoã®ããã¯ãšã³ãã䜿çšããŠå¿ èŠãªæ€çŽ¢ã¯ãšãªãäœæããçµæãDjangoã¢ãã«ãšããŠè¿ããŸãããïŒ èª°ãããããè¡ãããšããå§ãããŸããããããã¯æ¬åœã«ããã»ã©æãã§ã¯ãããŸããã ãããŠããŸã æãããŸãã¯åã«èå³ããªã人ã®ããã«ã次ã®ã»ã¯ã·ã§ã³ã«ããã«é²ãããšããå§ãããŸãã
ãã€ãã®ããã«ãgithubã«ã¯äŸ¿å©ãªãã®ããããŸãã ããšãã°ãåãdjango-sphinx-db㯠ãdjangoã¢ãã«ããçŽæ¥ãšã³ãžã³ãéå§ããã®ã«åœ¹ç«ã¡ãŸããã Django-1.8ã§ã¯ãããŒã¿ããŒã¹ããã¯ãšã³ãå®è£
ã®ãã©ã€ããŒãéšåã倧å¹
ã«å€æŽãããããã django-sphinx-db
移æ€ãåé¡ã«ãªããŸããã ãã®çµæã django-sphinxsearchãããžã§ã¯ããç»å ŽããŸãããããã¯ãéçºåŽããã®æ³šæãå°ãæ¬ ããŠããŸããã ãã§ã«æ¬çªç°å¢ã§äœ¿çšãããŠããŸãã ã¡ãªã¿ã«ãããã«ããã¯ãšã³ããµããŒãã®é£ããã®äŸããããŸããDjangoã®æ°ããããŒãžã§ã³ããªãªãŒã¹ããããã¹ãŠããã©ãã©ã«ãªããŸãããªããªãããç§ã®å
èã¯ç§ãæããã®ãå€ãããããã§ãã ã§ããããæåããå§ããªããã°ãªããŸããã
次ã®ããã«ãªããŸãã
- PEP-0249äºæã®ããŒã¿ããŒã¹ã³ãã¯ã¿ãæ¢ããŠããŸãã MySQL-pythonãpsycopgãpython_monetdb-Djangoã®ãã蟌ã¿å ã«ãã£ãŠç°ãªããŸãã
- 粟ç¥çã«æãè¿ãããã¯ãšã³ããååŸãããç¶æ¿ãããŸãã sphinxsearchã®å Žåãããã¯MySQLãå¥å
django.db.backends.mysql
ã§ãã - æãé£ããã®ã¯ãããã¯ãšã³ããèšè¿°ãããŠããããŒã¿ããŒã¹ãšäºææ§ã®ããã³ãŒã
SQLCompiler
çæããããã«SQLCompiler
ã«æããããšã§ãã ããã¯ãåŒçšç¬Šã®äœ¿çšãã¹ããŒããæå®ããã«ããŒãã«åãæå®ããæ©èœãLIMIT / OFFSETæ§æãªã©ã«é©çšãããŸãã ããã§ãSQLCompiler.as_sql
ããæååãåéããSQLCompiler.as_sql
ã¡ãœãããã»ãŒ100è¡ã®ã¢ããªã¹ã§ãããšããäºå®ã«ã€ããŠãDjangoéçºè ã«å¥ã®ãåŠç²ŸããèšããããšæããŸãã ãã®çµæãLIMIT OFFSET
ãLIMIT start, end
ã«å€æŽããã«ã¯ãåºæ¬ã¯ã©ã¹ã¡ãœãããåŒã³åºããçµæãå®æçã«LIMIT start, end
ããããŸãã - æ€çŽ¢åºæã®æ©èœãæäŸããQuerySetã¡ãœãããè¿œå ãããŸããã ããšãã°ã
SphinxQuerySet.match
ã¯self.matchæ§é ãSphinxQuerySet.match
è¿œå ããSphinxQLåŒã®æ§ç¯ã«å¿ èŠãªããŒã¿ãå«ãŸããŸãã äžèŽãã£ãŒã«ãã¯è€è£œãããSphinxWhereNode.make_atom
ã§å€æŽãããæåŸã«SphinxWhereNode.make_atom
䜿çšãããŠã¯ãšãªæååã®äžéšãçæããŸãã è€éãªããšã¯äœããããŸããããã¹ããæžããŠãæå ã«è¯ããããã¬ãçšæããã ãã§ãã
æ€çŽ¢çµæã©ã³ãã³ã°
éåžžãæ€çŽ¢çµæã¯ãæ€çŽ¢ã¯ãšãªãšã®é¢é£æ§ã«ãã£ãŠãœãŒããããŸãã ãããæ°ããã«ã¯ïŒ ããšãã°ãããã¥ã¡ã³ããšã¯ãšãªã«åæã«ååšããåèªã®æ°ãååŸã§ããŸãã 亀差ç¹ã®åèªãå€ãã»ã©ããã®ã¯ãšãªã«ããæ£ç¢ºã«çµæãé©åããŸãã äžèŽããåèªã®æ°ã ãã§ãªãããããã®é åºãèæ ®ããããšãã§ããŸãã ãããŠãååèªã®ãåžå°æ§ããèæ ®ãããå Žåãããã¯äžè¬çã«ã¯ãŒã«ã§ãããªã¯ãšã¹ãããã³ããã¥ã¡ã³ãå ã®å眮è©ãšæ¥ç¶è©ã®ååšã¯ããã¯ãåé¡ã«åœ±é¿ããŸããã ãã®ãããªç¹æ§ãçºæããå€ãã®ç°ãªããæçšãªããããŠããã»ã©å€ãã¯ãªãã®ã§ãäžè¬çãªã±ãŒã¹ã§ã¯ããšã³ãžã³ãèæ ®ãããã¹ãŠã®ç¹æ§ã®å€ã®å éåã䜿çšããã®ãåççã§ãã
ç¹å®ã®ããã¥ã¡ã³ããæ€çŽ¢ã¯ãšãªã«é¢é£ä»ããç¹æ§ã«å ããŠãã¯ãšãªã«é¢ä¿ãªããç¹å®ã®å±æ§ãæã€ããã¥ã¡ã³ãã«éã¿ãè¿œå ããããšãã§ããŸãã ããšãã°ãé«å質ã§ããŒãããããããªã®åºåãå¢ããããã ãŸãã¯ãæè¿ã®åç»ãèŠèŽåæ°ã®å€ãåç»ã«éã¿ãä»ããŸãã
ãªã¯ãšã¹ãã«è¿œå ããŸã
SELECT weight() + a * view_count + b * age as my_weight, ... OPTION ranker=expr('...') ORDER BY my_weight DESC;
ãŸããçºè¡ã®ãœãŒãé ã¯å®å šã«ç®¡çãããŠããŸãã
ãã®ãããç°¡åãªæ¹æ³ã§æ¬¡ã®ããã«ãªããŸã
- ã©ã³ãã³ã°åŒã®äžè¬çãªãã¥ãŒ
- åã ã®ãã£ãŒã«ãã®éã¿ïŒã¿ã€ãã«-説æã®10åéèŠïŒ
- åã ã®ç¹æ§ã®éã¿
- æ€çŽ¢ã¯ãšãªãšãäžèŽãããçµæã«å¯Ÿããè¿œå ã®ããŒãã¹
QuerySet.iteratorïŒïŒ
ïŒç·šéè
ã¯ããããã®ããããããååã§ãªãããšãã»ã®ããããŠããŸãïŒ
æ€çŽ¢ã¯ãšãªã®èª¿æŽã ãã§ã¯äžååãªå Žåã¯ãçµæãçªã§ãéä»ããã§ããŸãã äžéšã®ã¯ãšãªã§ã¯ãããã¯äžè¬ã«éèŠãªæ©èœã§ãããããå¿ èŠã§ã¯ãããŸããããæ€çŽ¢çµæãæäœããã¡ã«ããºã ãå®è£ ããå¿ èŠããããŸãã
- ç·šéè ãæ€çŽ¢çµæã«è¡šç€ºãããçŸåšã®ãªã¯ãšã¹ãã®åç»ããããã©ãããæ¢ããŠããŸãã ããããå æãããŠããäœçœ®ãååŸããŸãã
- ããã€ã«ãçµæ以å€ã®æ€çŽ¢ããªã¯ãšã¹ãããŸãã
- QuerySet.iterator
QuerySet.iterator()
ã¡ãœãããå€æŽããŠããéåžžãç¶æ ã®sphinxsearchããã®çµæãè¿ããäžéšã®å Žæã§åããéä»ããã¯ãªãããè¿ãããã«ããŸãïŒããšãã°ããRealç·ã®åããã³ã¡ã³ããªããã - æ€çŽ¢ã§ç¡é¢ä¿ãªçµæãçæãããå Žåãäžè¬çã«ãããšãã°ãé¡äŒŒã®ã¯ãªããã®ä»£ããã«ãããŒã¿ããŒã¹ããäœããããšãã°åãã·ãªãŒãºã®ãšããœãŒãã®ãªã¹ãã衚瀺ã§ããŸãã ãããè¡ãã«ã¯ãã¡ã€ã³Videoã¢ãã«ãSearchVideoæ€çŽ¢çµæã®ã¢ãã«ãšãã£ãŒã«ããäžèŽãããã ãã§ååã§ãã
æè¡çãªå¶é
sphinxsearchã§ã§ããªãããšã«ã€ããŠå°ã説æããŸãã æãå¥åŠã§ãåæã«èª¬æäžå¯èœãªãäžå¯èœãïŒ1ã€ãŸãã¯è€æ°ã®ææžãé€ããŠãã¹ãŠã®çºè¡ãçºè¡ããããšã¯äžå¯èœã§ãã ãã«ã¹ãã£ã³ã ããå®è¡ã§ããŸããããã«ã¹ãã£ã³WHERE MATCH('~document_id')
ãdocument_id WHERE MATCH('~document_id')
ã¯å®è¡ã§ããŸããã ãœãããŠã§ã¢ã¯ãéå¹ççã«çŠæ¢ããŠããŸãã
å¶éã«ã¯2ã€ã®å¶éããããŸããæåã«ãæ瀺çã«LIMITãæå®ããªãSELECT *
ãã»ãŒrepr(queryset)
ãããª20ã®çµæãè¿ããŸãã 次ã«ã100500çªç®ã®èŠçŽ ãèŠã€ããã«ã¯ãã¯ãšãªã«OPTION max_matches=100500
ãè¿œå ããŸãã ãšã³ãžã³å
ã«ã¯éšåçãªäžŠã¹æ¿ãããããæ¢å®ã§ã¯ãŠã£ã³ããŠãµã€ãºã¯1000ã§ãããã®çµæããã倧ããªãªãã»ãããèŠæ±ãããšãšã©ãŒã«ãªããŸãã
å±æ§ãæã€æ°å€æŒç®ã«ã¯å€ãã®å¥åŠãªå¶éããããŸãã äŸãã°ã SELECT
ã§ã¯float_field <> 3.1415
èšè¿°ã§ããŸããã WHERE
ã§ã¯èšè¿°ã§ããŸããã äœãã§ããããç¹ã«ããŒãµãŒã QuerySet.extra()
ãä»ããŠæŠããŸãã
æãäžå¿«ãªãäžå¯èœãïŒæãäžå¿«ãªç¬éã«æ€çŽ¢ãã¯ã©ãã·ã¥ããªããšããäºå®ã«é Œãããšã¯ã§ããŸããã çªå·ã13ããå«ããªã¯ãšã¹ããåä¿¡ããçŽåŸã«searchdãåèµ·åããå ŽåããããŸããã ããã¯ãæ€çŽ¢çµæãäž»èŠãªã³ã³ãã³ãã§ã¯ãªãããŒãžã§ã¯ç¹ã«äžå¿«ã§ãã ãžã§ãã¬ãŒã¿ãŒã§ç®¡çããŸãããOperationalErrorãåãåã£ãå Žåãéãã«å¹³åçã«ç©ºã®å¿çãè¿ããŸãã
è² è·ãããã£ãŠãã
ãµã€ãã«å€ãã®ããŒã¿ããããããããé »ç¹ã«å€æŽãããç¶æ³ã§ã¯ã5åããšã«ãµã€ãå šäœãååŸããŠã€ã³ããã¯ã¹ãäœæããããšã¯ã§ããŸããã ãã£ãšè³¢ããªããã°ãªããŸããã æ€çŽ¢ã§ãç¬ãé£ã¹ãã人ã«ãšã£ãŠããã®ã»ã¯ã·ã§ã³ã¯ããŸãé¢çœããããŸããããªããªããç©äºã¯ã»ãšãã©ããç¥ãããŠããããã§ããããããç§ã¯ããããç°¡æœã«èŠç¹ãŸã§èª¬æããŸãã
ã¡ã€ã³+ãã«ã¿+ãã«ãªã¹ãã main-ãµã€ãå šäœãå«ãã¡ã€ã³ã€ã³ããã¯ã¹ã¯1æ¥ã«1åæŽæ°ãããŸãã delta-ã¡ã€ã³ã€ã³ããã¯ã¹ã®æåŸã®ã€ã³ããã¯ã¹äœæ以éã«æŽæ°ãããããã¥ã¡ã³ãã®ã¿ãå«ãŸããŸãã killlist- åã®ã€ã³ããã¯ã¹ããé€å€ããå¿ èŠãããããã¥ã¡ã³ãã®ãªã¹ãã
# IP sql_query_pre = set @ip = substring_index(user(), '@', -1); # delta- KILL- # , delta- + # , main sql_query_killlist = select id from ... where ... and last_updated_ts > @last_index_ts
- global_idf è€æ°ã®ããŒã«ã«ã€ã³ããã¯ã¹ãããå Žåãglobal_idf = 1ãã©ã¡ãŒã¿ãæå®ãã䟡å€ããããŸãã ããã§ãªãå Žåãéããã¥ã¡ã³ãé »åºŠã¯ã€ã³ããã¯ã¹ããšã«åå¥ã«èæ ®ãããŸãããã®çµæãããã«ã¿ãããã®ããŸããªãåèªãååšããªãã¯ãã®çµæãæŒãäžããŸãã
- ããã€ãã®æ€çŽ¢ãšã³ãžã³ã æ€çŽ¢ãšã³ãžã³ã®ã€ã³ããã¯ã¹ãã¡ã€ã«ã®è€è£œã«ã€ããŠã¯è³¢ããªãããåãµãŒããŒãåå¥ã«ããŒã¿ããŒã¹ã®ã€ã³ããã¯ã¹ãäœæããŸãã åæãåããŠããªãããŒã¿ãçºçããããã«å®å®ãããœãªã¥ãŒã·ã§ã³ãçºæãããŸãããããããŸã§ã®ãšããæãå±ããŸããã§ããã 解決çïŒRT-indexãããã¥ã¡ã³ãã®å€æŽã«é¢ããã¡ãã»ãŒãžãåä¿¡ãããšããã¹ãŠã®æ€çŽ¢ãšã³ãžã³ã§åæã«æŽæ°ãããŸãã é·æïŒã€ã³ã¹ã¿ã³ãã€ã³ããã¯ã¹äœæãéåžžç¶æ ã§ã®ããŒã¿rassynchronã®æ¬ åŠã çæïŒéå§ã³ãŒããéä¿¡ããéåžžã«è€éãªã¡ãã»ãŒãžã æ€çŽ¢ããã¥ã¡ã³ãã«ã¯ãçŽ15ã®ããŒã¿ããŒã¹ããŒãã«ããã®ããŒã¿ãå«ãŸããŠãããåæ€çŽ¢ãµãŒããŒã«ã¡ãã»ãŒãžãã³ãã©ãå¿ èŠã§ãã
- ãµãŒããŒã®è² è·ã ãã¡ãããLoadãCPUã®100ïŒ
ã«ããªãæ¹ãè¯ãã§ããããããæšæºã«ãªã£ãŠããå Žåã¯ãçè«çãªã¯ãšãªå®è¡æéãå¶éãã
max_predicted_time
ãªãã·ã§ã³ããããŸãã é¢é£æ§ã¯äœäžããŸãããåé¡ã®äžéšã¯åæžã§ããŸãã ãç¥ã¯ãã¹ãŠãèŠããã®ã§ãå¯èœã§ãããå¿ èŠã§ã¯ãããŸããã ç¥ã¯ç·šéè ã§ããããã¹ãŠã¯ãããšãã°ãããŒãžäžã®éåžžã«å¥åŠãªãé¡äŒŒããããã®ã®å€èŠ³ã§ãã äžæçãªéè² è·ã«CONN_TIMEOUT
ã¯ãDjangoæ¥ç¶ã«CONN_TIMEOUT
ãèšå®ããŠãæ€çŽ¢ãä»ã®ãã¹ãŠã®é床ãäœäžãããªãããã«ããã®ãçã«ããªã£ãŠããŸãã - å矩èªãšäŸå€ãªã¹ãã®ç®¡çã ãããWebDAVã§å解ããæãè¿ãã€ã³ããã¯ã¹ä»ãã§ïŒã€ã³ããã¯ã¹ã®å転äžã«ïŒé©çšããŸãã
RTã€ã³ããã¯ã¹ã®å€æŽã«ã€ããŠ
ããã§ããsphinxsearchã¯ããŒã¿ããŒã¹ã§ã¯ãããŸããã ãã ãããã®äžã®ããŒã¿ãå€æŽããå¯èœæ§ããããŸãã
-
UPDATE
ã§ã¯ãåºå®é·ã®å±æ§ãUPDATE
ã§ããŸãã ãšããã§ããªã³ãã£ã¹ã¯ã€ã³ããã¯ã¹ã§ãã - ãã以å€ã®å Žåã¯ã
REPLACE
䜿çšãããå€ãããŒãžã§ã³ã®ããã¥ã¡ã³ããåé€ãããæåŸã«æ°ããããŒãžã§ã³ãè¿œå ãããŸãã - ãããã£ãŠãDjangoã®ããã¯ãšã³ãéçºè
ã«ãšã£ãŠã®å°é£ã¯ããŸãã
queryset.update(field=value)
ã¯æ°å€å±æ§ã«å¯ŸããŠã®ã¿æ©èœããREPLACE
ã¯äžæ¬æ¿å ¥ãšããŠãã©ãŒãããããå¿ èŠããããŸãã 第äºã«ãREPLACE
æ§æã¯INSERT
ãšããã«é¡äŒŒããŠããŸããSQLInsertCompiler
ã䜿çšããŠSQLInsertCompiler
ããå¿ èŠãããSQLInsertCompiler
ã äžè¬çã«ãèããã¹ãããšããããŸãã
çç£ã§3幎ésphinxsearchã䜿çšããåŸãæ€çŽ¢ããŒã å šäœãæ ç±çãã€å¿ãã圌ãæããŠããŸããã ãããããããã¯ãã¹ãŠã®åé¡ããšãŠãå¥åŠã§é¢çœãå¯äžã®ãããžã§ã¯ãã§ã:)
- DSPH-146èµ€ã¡ãããšçªæ
- DSPH-115ãã ã¹ã¿ãŒãå£ããŠããŸãïŒæ€çŽ¢çµæïŒ
- DSPH-129ã¯ãé¡äŒŒã®åç»ããåãåç»ãåé€ããããšã«åæããŸãã
- DSPH-118æªãé¡äŒŒãéåžžã«æªã
- DSPH-131åã³äŒŒããããªãåã³å«ãª
Rutubeã®sphinxsearchã¯ãKibanaèªè»¢è»ã®ãã°ãä¿åããã³åŠçããããã«äœ¿çšãããŸã-ã¡ãªã¿ã«ãããªãé«éã«åäœããŸãã æéããããŸã-圌ã«ã€ããŠã話ããŸãã