Linux and c-based inverted index-general Linux technology-Linux programming and kernel information. For more information, see the following. Original: zfzgodfather
This program is a local search program based on the inverted index principle in linux and c. There are two parts: the statistical part and the search part.
Statistics:
1. First, the user provides the path for statistics and starts to traverse down. Based on the suffix, the user filters out the files to be counted, numbers from scratch, and writes the files named "textfile. t.
2 from textfile. t reads the files to be counted, extracts the strings, corresponds to the document number, and writes the sorted strings to the files with the suffix "I" in memory, each such file can write up to 150000 units. At this point, we will get a lot of files with the suffix "I". These files are alphabetically in a single file and are unordered as a whole.
3. Use a multi-path merging Tree to merge these files. after a certain number of files are stored on the hard disk, a series of files with the suffix "inv" are generated.
4. process the inv file, sort the document number after the keyword (string), and record the number of times each word is in the document. Generate a file with the suffix "ind.
5. During the inv file generation process, record the first string of each file and correspond to the document to generate "Bfile. t "file (B tree) to prepare for secondary indexing. Search part:
First, set textfile. t file, Bfile. t file is read into the memory, and then binary search for Bfile Based on the string you want to provide. t file in the memory ing table, get the ind file name where the keyword is located, read the file into the memory, then search for the file in two minutes to get the document number of the file, and then in textfile. t file in the memory ing table find the path name and print it out. The order of printing is not processed. If multiple search strings exist, the search results are Boolean calculated and the intersection is obtained. The file paths containing all these strings are printed.
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