Recommend this page to a friend! |
Classes of Necip | NCP Search | README.md | Download |
|
Downloadncp_search engine - the basic ideaWhy this post?The amount of data increases every day. As a result, the search in the databases becomes longer and longer. Conventional data structures must be realigned in order to be able to access information more quickly.There are already database systems like Elasticsearch that can do this. However, such systems also have disadvantages. There are no advantages without disadvantages! The most noticeable major drawbacks are: - Learning a new query language. SQL won't get you far. - The existing programs must be rewritten in order to process the new result sets appropriately. - The safety regulations must be defined again. - A second database must be set up, which in principle contains the same data. Who will benefit from this post?This information is useful for any programmer who wants to integrate an index database into his existing system in a simple and elegant way without additional effort. What we will and will not cover?... The basic idea behind Indexing-machines like ElastisearchWe will use this simple Table to demonstrate what an Index-machine does Tablename: object | UID | Title | Description | |------|-------------------|--------------------------------------------------------------------------------------------| | 4711 | Rudyard Kipling | If you can keep your head when all about you ... | | 4712 | John Magee | I have slipped the surly bonds of Earth and danced the skies on laugher-silvered wings ... | | 4713 | Wiliam Wordsworth | Ten thousand saw I at a glance, Tossing their heads in sprightly dance... | With this request we can find very specific texts in this single table:
But what if we want to find '%head%' in all tables of our database? We have to write a code to do this job for us. This is inefficent and will work very slowy. The idea behind Elasticsearch and other indexing tables is - so far I understood - to break the strings in single tokens. That means in a very easy way that we have to transform the horicontal order of the table into a vertical order. Tablename: ncp_index | UID | Tablename | Fieldname | ID | Token | |------|-----------|-------------|------|---------| | 1001 | object | Description | 4711 | if | | 1002 | object | Description | 4711 | you | | 1003 | object | Description | 4711 | can | | ... | | | | | | 1010 | object | Description | 4712 | I | | 1011 | object | Description | 4712 | have | | 1012 | object | Description | 4712 | slipped | | ... | | | | | We can tokenize any field of any table of our database into the table ncp_index. Now we can find with a single query very fast any (tokenized) word in our hole database.
That is the revealed secret of an Index-Searchengine like Elastisearch. Yes, the ncp_index table has a lot of redundant data that we can normalize as follows:
Our ncp_index table looks now so: | UID | Field_id | ID | Token_id | |------|----------|------|----------| | 1001 | 123 | 4711 | 1 | | 1002 | 123 | 4711 | 2 | | 1003 | 123 | 4711 | 3 | | ... | | | | | 1010 | 123 | 4712 | 4 | | 1011 | 123 | 4712 | 5 | | 1012 | 123 | 4712 | 6 | | ... | | | | Systemtable: fields | UID | Tablename | Name | |-----|-----------|-------------| | 122 | object | Name | | 123 | object | Description | | ... | | | Tablename: word | UID | Token | |-----|-------| | 1 | if | | 2 | you | | 3 | can | |... | | Some basic examples
ConclusionThese are my basic observations on this subject. They are the first steps to a powerful machine that can index existing tables so that informations can be found quickly. Thanks to
Contactnecips@live.de |