Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
organization
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Johnson committed Dec 22, 2011
1 parent 6593751 commit fe1a5b9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
25 changes: 15 additions & 10 deletions bin/git-search
@@ -1,12 +1,19 @@
#!/bin/sh

GIT_BASE=`git rev-parse --show-toplevel`
help()
{
echo 'Usage:'
echo ' git-search --index'
echo ' git-search <search terms>'
}

REPO_BASE=`git rev-parse --show-toplevel`
if [ 0 -ne $? ]; then
echo $GIT_BASE
echo $REPO_BASE
exit 1
fi

INDEX="$GIT_BASE/.gitsearch/index"
INDEX="$REPO_BASE/.gitsearch/index"

SOURCE=$0
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
Expand All @@ -17,12 +24,10 @@ export CLASSPATH="$GIT_SEARCH_BASE/lucene-core-3.5.0.jar:$GIT_SEARCH_BASE/src"

COMMAND=$1

if [ $COMMAND == 'index' ]; then
java org.apache.lucene.demo.IndexFiles -index $INDEX -docs $GIT_BASE
elif [ $COMMAND == 'query' ]; then
java org.apache.lucene.demo.SearchFiles -index $INDEX -query $2
if [ -z $COMMAND ]; then
help
elif [ $COMMAND == '--index' ]; then
java com.github.tenorviol.gitsearch.IndexFiles -index $INDEX -docs $REPO_BASE
else
echo 'Usage:'
echo ' git-search index'
echo ' git-search query <search terms>'
java com.github.tenorviol.gitsearch.SearchFiles -index $INDEX -query $COMMAND
fi
3 changes: 3 additions & 0 deletions makefile
@@ -0,0 +1,3 @@

src/com/github/tenorviol/gitsearch/*.class: src/com/github/tenorviol/gitsearch/*.java
javac -classpath lucene-core-3.5.0.jar src/com/github/tenorviol/gitsearch/*.java
Binary file not shown.
@@ -1,4 +1,4 @@
package org.apache.lucene.demo;
package com.github.tenorviol.gitsearch;

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down
Binary file not shown.
@@ -1,4 +1,4 @@
package org.apache.lucene.demo;
package com.github.tenorviol.gitsearch;

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void main(String[] args) throws Exception {
boolean raw = false;
String queryString = null;
int hitsPerPage = 10;

for(int i = 0;i < args.length;i++) {
if ("-index".equals(args[i])) {
index = args[i+1];
Expand Down Expand Up @@ -85,7 +85,7 @@ public static void main(String[] args) throws Exception {
i++;
}
}

IndexReader reader = IndexReader.open(FSDirectory.open(new File(index)));
IndexSearcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
Expand All @@ -112,10 +112,10 @@ public static void main(String[] args) throws Exception {
if (line.length() == 0) {
break;
}

Query query = parser.parse(line);
System.out.println("Searching for: " + query.toString(field));

if (repeat > 0) { // repeat & time as benchmark
Date start = new Date();
for (int i = 0; i < repeat; i++) {
Expand All @@ -136,28 +136,28 @@ public static void main(String[] args) throws Exception {
}

/**
* This demonstrates a typical paging search scenario, where the search engine presents
* This demonstrates a typical paging search scenario, where the search engine presents
* pages of size n to the user. The user can then go to the next page if interested in
* the next hits.
*
*
* When the query is executed for the first time, then only enough results are collected
* to fill 5 result pages. If the user wants to page beyond this limit, then the query
* is executed another time and all hits are collected.
*
*
*/
public static void doPagingSearch(BufferedReader in, IndexSearcher searcher, Query query,
public static void doPagingSearch(BufferedReader in, IndexSearcher searcher, Query query,
int hitsPerPage, boolean raw, boolean interactive) throws IOException {

// Collect enough docs to show 5 pages
TopDocs results = searcher.search(query, 5 * hitsPerPage);
ScoreDoc[] hits = results.scoreDocs;

int numTotalHits = results.totalHits;
System.out.println(numTotalHits + " total matching documents");

int start = 0;
int end = Math.min(numTotalHits, hitsPerPage);

while (true) {
if (end > hits.length) {
System.out.println("Only results 1 - " + hits.length +" of " + numTotalHits + " total matching documents collected.");
Expand All @@ -169,9 +169,9 @@ public static void doPagingSearch(BufferedReader in, IndexSearcher searcher, Que

hits = searcher.search(query, numTotalHits).scoreDocs;
}

end = Math.min(hits.length, start + hitsPerPage);

for (int i = start; i < end; i++) {
if (raw) { // output raw format
System.out.println("doc="+hits[i].doc+" score="+hits[i].score);
Expand All @@ -189,7 +189,7 @@ public static void doPagingSearch(BufferedReader in, IndexSearcher searcher, Que
} else {
System.out.println((i+1) + ". " + "No path for this document");
}

}

if (!interactive || end == 0) {
Expand All @@ -201,13 +201,13 @@ public static void doPagingSearch(BufferedReader in, IndexSearcher searcher, Que
while (true) {
System.out.print("Press ");
if (start - hitsPerPage >= 0) {
System.out.print("(p)revious page, ");
System.out.print("(p)revious page, ");
}
if (start + hitsPerPage < numTotalHits) {
System.out.print("(n)ext page, ");
}
System.out.println("(q)uit or enter number to jump to a page.");

String line = in.readLine();
if (line.length() == 0 || line.charAt(0)=='q') {
quit = true;
Expand Down

0 comments on commit fe1a5b9

Please sign in to comment.