Opengrok Add the ability to query filtering based on the file name suffix

Source: Internet
Author: User

<span style= "font-family:arial, Helvetica, Sans-serif; Background-color:rgb (255, 255, 255); " >opengrok Default will *.O *.so these binaries are also indexed (in fact, no harm), if you want to filter these files in the query, how to do? </span>


Points:

Https://github.com/OpenGrok/OpenGrok/blob/master/src/org/opensolaris/opengrok/index/IgnoredNames.java

Ignorednames is the default index filter, which matches the file path as a string.


Https://github.com/OpenGrok/OpenGrok/blob/master/src/org/opensolaris/opengrok/search/SearchEngine.java

You can modify the searchsingledatabase and searchmultidatabase here .

    private void Searchsingledatabase (File root, Boolean paging) throws IOException {        Indexreader ireader = Directoryread Er.open (Fsdirectory.open (root));        Searcher = new Indexsearcher (ireader);        Collector = Topscoredoccollector.create (hitsPerPage * cachepages, docsscoredinorder);        Searcher.search (query, collector);        Totalhits = Collector.gettotalhits ();        if (!paging && totalhits > 0) {            collector = Topscoredoccollector.create (totalhits, Docsscoredinorder); C8/>searcher.search (query, collector);        }        hits = Collector.topdocs (). Scoredocs;        for (Scoredoc hit:hits) {            int docId = Hit.doc;            Document d = Searcher.doc (docId);            Docs.add (d);        }    }

Note that there are 2 modifier points: Modify the implementation of the collector so that if the file name suffix is *.so *.o, it does not collect, or modifies the condition of the document Add.

Modify collector is not OK, because TopScoreDocCollector is the Lucene class, and I just want to change Opengrok. Modifying the condition of the document add is more convenient, the question is: How to get the "filename suffix" information from the Document object?

You cannot find a clue in the Org/opensolaris/opengrok/search package and look at the index module.

Https://github.com/OpenGrok/OpenGrok/blob/master/src/org/opensolaris/opengrok/index/IndexDatabase.java


You can get a full path string. The filename suffix information can be extracted from it. The question is, is it possible to get this information directly? Check QueryBuilder code:
/*** fields We use the Lucene public ones*/public static final string full = "full";p ublic static final String DEFS = "DEFS ";p ublic static final String refs =" refs ";p ublic static final string path =" path ";p ublic static final String HIST =" his T ";p ublic static final String type =" type ";
No. Here the Hist field does not know what it means.

The above modifications can work, but may result in inconsistent page display. A more complete modification should be to provide your own custom filter at search time:

Https://lucene.apache.org/core/4_0_0/core/org/apache/lucene/search/FieldValueFilter.html

Https://lucene.apache.org/core/4_0_0/core/org/apache/lucene/search/FieldCacheTermsFilter.html

What to do, no time to study. The built-in filter class appears to be includes semantics, not excludes semantics, so you might also need to provide your own custom implementation.

Opengrok Add the ability to query filtering based on the file name suffix

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.