Use Python and Django to call your sphinx series (5)

Source: Internet
Author: User

Official sphinx APIs include PHP, Python, Java, Ruby, and pure C. Other open-source APIs are as follows:

    • Perl API port, Sphinx: search, by Jon Schutz
    • C ++ API port, C ++ sph?client, by seznam. cz
    • Haskell API port, Haskell sphsf-client, by tupil
    • C # API port, C #. Net client, by Christopher gooley

Put the sphsf-api file in the API directory of the downloaded source file and enter the directory to see the following files: CD/USR/Local/SRC/Sphinx-0.99/API/

Drwxr - XR - X 2 Chenzehe 4096   2009 - 12 - 02 Java
Drwxr - XR - X 2 Chenzehe 4096   2009 - 12 - 02 Libsphinxclient
Drwxr - XR - X 5 Chenzehe 4096   2009 - 12 - 02 Ruby
- RW - R -- R --   1 Chenzehe 44399   2009 - 11 - 07 Sphinxapi. php
- RW - R -- R --   1 Chenzehe 26251   2009 - 11 - 07 Sphinxapi. py
- RW - R -- R --   1 Chenzehe 1053   2007 - 11 - 16 Test2.php
- RW - R -- R --   1 Chenzehe 579   2006 - 11 - 23 Test2.py
- RW - R -- R --   1 Chenzehe 5656   2009 - 11 - 07 Test. php
- RW - R -- R --   1 Chenzehe 3331   2009 - 11 - 07 Test. py

Sphinxapi. py is a python API, and test. py and test2.py are test instances of this API.

 

Start the searchd daemon:

Go to the bin folder of the Sphinx installation directory and see the following files:

[Root @ localhost bin] # Ls-L/usr/local/coreseek/bin/
Total 25436
- Rwxr - XR - X 1 Root 5144646   11 - 14   15 : 14 Indexer
- Rwxr - XR - X 1 Root 4971942   11 - 14   15 : 14 Indextool
- Rwxr - XR - X 1 Root 5032457   11 - 14   15 : 14 Search
- Rwxr - XR - X 1 Root 5883521   11 - 14   15 : 14 Searchd
- Rwxr - XR - X 1 Root 4920843   11 - 14   15 : 14 Spelldump

The Chinese word segmentation component coreseek is installed, so the installation directory is placed under coreseek. If this component is not installed, these installation is also in the binfile under the installation directory of sphinx,

Where:

Indexer is a tool for creating indexes;

Search is a simple command line (CLI) testProgramTo test the full-text index;

Searchd: A daemon. Other software can use this daemon for full-text retrieval;

Spelldump: A simple command line toolIspellOrMyspell(OpenOffice built-in binding. You can use these terms to customize indexes when using wordforms;

Indextool: A Tool program used to dump debugging information about Multiple indexes. This tool is added from coreseek 3.1 (sph00000.9.9-RC2;

 

As shown above, only the searchd process can be started for the application to search. Run the file to start the process, as shown below:

[Root @ localhost bin] # /Usr/local/coreseek/bin/searchd # Start Searchd Process
[Root @ localhost bin] # PS # view the searchd Process
PID tty time cmd
  4388 PTS / 1 00 : 00 : 00 Bash
  6306 PTS / 1 00 : 00 : 00 Mysqld_safe
15692 PTS / 1 00 : 00 : 00 Searchd
16139 PTS / 1 00 : 00 : 00 PS

 

At this time, the searchd process has been started. Run the test. py test file to check the running effect:

[Root @ localhost bin] # Python/usr/local/src/sphsf-- 0.9.9/API/test. py Test # Test is the search keyword
Query ' Test ' Retrieved 3 Of 3 Matches In   0.004 Sec
Query stats:
' Test ' Found 10 Times In   6 Documents

Matches:
1 . Doc_id = 1 , Weight = 101 , Group_id = 1 , Date_added = 2010 - 11 - 14   16 : 36 : 36
2 . Doc_id = 2 , Weight = 101 , Group_id = 1 , Date_added = 2010 - 11 - 14   16 : 36 : 36
3 . Doc_id = 4 , Weight = 1 , Group_id = 2 , Date_added = 2010 - 11 - 14   16 : 36 : 36

You can also run this test in eclipse, open eclipse, create a python project, and set sphinx. PY, test. copy Py and test2.py to the project directory and set test. if the parameter is "test" during py running, click "test. py-> right-click-> Run as-> RUN configuration-> arguments, and enter the runtime parameter test in it to output the same result as above.

 

Django needs to call sphinxDjango-SphinxThe Project address is https://github.com/dcramer/django-sphinx. the official introduction is as follows:

This is a layer that functions much like the Django ORM does plugin t it works on top of the Sphinx full-text search engine.

Please note: you will need to create your own sphinx indexes and install sphinx on your server to use this app.

Download from http://pypi.python.org/pypi/django-sphinx/ for installation:

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.