⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchcmd.cpp

📁 These are precompiled demonstration programs of the Onix toolkit. They do not include the Onix tool
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		vector = ixProcessQuery( theIndexManager, (UCharT *) NULL, (UCharT *) q_bhex, &theStatus );

	}
	

	if ( theStatus < 0 )
		return NULL;

	return vector;
}



// make_choice
// -----------
// The main interface for the interactive mode.   Displays the maximum number 
// of hits and records.  It then prompts for a new query or a hit number to
// display.  Note that this deletes the vector so as to free memory.

int make_choice()
{
	char				choice[10];
	ULongT 				hits, records, temp ;
	OnixQueryVectorT	Results;

	hits = 0;
	records = 0;

	Results = get_query();

	// Get stats about the number of records and hits for the query
	ixNumHits( Results, &hits, &records, &temp, &theStatus);
			
	if ( theStatus < 0 ) {
		printf("\nError in Query\n");
		return -1;
	}


	for (;;) {
		// Print out the stats (initially zero)
		printf("\nCurrent Query: Hits: %d          Records: %d\n",hits, records);

		printf("\n(E) Exit   (N) New Query    (#) Display Hit Number #\n");
		scanf("%s",choice);

		switch ( choice[0] ) {
		case 'E': 
		case 'Q':
		case 'e':
			ixDeleteResultVector( Results, &theStatus);
			return 0;
			break;

		case 'n':
		case 'N':
			ixDeleteResultVector( Results, &theStatus);

			// Get a query and it's result
			Results = get_query();	

			// Get stats about the number of records and hits for the query
			ixNumHits( Results, &hits, &records, &temp, &theStatus);

			if ( theStatus < 0 ) {
				printf("\nError in Query\n");
				return -1;
			}

			break;

		default:
			temp = atoi(choice);	// convert choice to a number

			if ( ( temp <= 0 ) || ( temp > hits) ) {
				printf("\nThat is not a valid hit number.\n");
				break;
			}

			process_hit( Results, temp );
			break;

		}
	}

}

// search
// ------
// Handles the non-interactive version of the searching.  It sets up the 
// search parameters, processes the query, and displays the information.

void search()
{


	OnixQueryVectorT	vector;

	// Handles the query
	// -----------------

	char	q_rhex[255];	// string holding queries converted to hex
	char	q_bhex[255];

	if ( strlen( booleanquery ) == 0 ) {
		printf("\nNo query selected\n");
		return;
	}

	ixConvertQuery( (UCharT *) booleanquery, (UCharT *) q_bhex);


	if ( strlen( rankedquery ) == 0 ) {

		if ( Verbose_Mode )
			printf("\nNo ranking used...\n");

		vector = ixProcessQuery( theIndexManager, NULL, (UCharT *) q_bhex, &theStatus );

	}
	else {
		ixConvertQuery( (UCharT *) rankedquery, (UCharT *) q_rhex);
		vector = ixProcessQuery( theIndexManager, (UCharT *) q_rhex, (UCharT *) q_bhex, &theStatus );
		
	}


	// Display hit information
	// -----------------------

	ULongT 		hits, records, temp ;
	ixNumHits( vector, &hits, &records, &temp, &theStatus);

	if ( Display_Hits ) {
		printf( "Hits:     %d\n", hits);
		printf( "Records:  %d\n\n", records);	
	}

	if ( Display_Text ) {
		if (( first_hit <= 0 ) || ( first_hit > hits ) || ( last_hit > hits ) ) {
			printf("Selected hit out of range!\n");
			printf("Max hit: %d\n", hits);
			return;
		}

		int count;
		for( count = first_hit; count <= last_hit; count++ ) {
			process_hit( vector, count);
		}
	}

	// free vector
	ixDeleteResultVector( vector, &theStatus);

}

// print_help
// ----------
// Print out help information.

void print_help()
{
	printf( "\n");
	printf( "ONIX COMMAND LINE DEMO: Searching\n");
	printf( "---------------------------------\n");
	printf( "\n");
	printf( "search [-i] [-v] [-d] [-h] [-g #] [-r # #] [help] indexname booleanquery [rankedquery]\n");
	printf( "\n");
	printf( "  -i     (optional) interactive search \n");
	printf( "  -v     (optional) verbose mode (displays more information)\n");
	printf( "  -d     (optional) display text stored in index for hit \n");
	printf( "            (requires text to have been stored in index)\n");
	printf( "  -h     (optional) return # of hits \n");
	printf( "  -g #   (optional) return hit number # \n");
	printf( "            (default = 10 '\\n') \n");
	printf( "  -r # # (optional) return hits from # to # \n");
	printf( "            (default = 0) \n");
    printf( "  help   (optional) prints out this help information \n");
	printf( "\n");
	printf( "  indexname     full path to the index being opened \n");
	printf( "  booleanquery  the boolean query (put in quotes) \n");
	printf( "  rankedquery   (optional) the ranked query (put in quotes) \n");
	printf( "\n");
	printf( "Examples\n");
	printf( "\n");

}

// search [-i] [-v] [-d] [-h] [-g #] [-r # #] [help] indexname booleanquery [rankedquery]
//
// -i			(optional) interactive search 
// -v			(optional) verbose mode (displays diagnostic info)
// -d 			(optional) display text stored in index for hit (required text stored)
// -h			(optional) return # of hits
// -g #			(optional) get a single hit
// -r # #		(optional) get a range of hits (0 for last for all)
// 
// help			print help
// indexname	the name of the index to be created or opened
// booleanquery the boolean part of the query
// rankedquery  (optional) the ranked query

int main(int argc, char *argv[])
{

	if ( argc == 1 ) {
		// this is the default directory
		strcpy( IndexPath, "C:\\onix\\merge5\\Release\\test.idx");	


		if ( prepare_indexer() != 0 )
			return -1;
		make_choice();
		close_indexer();
		return 0;
	}

	enum arguments { in_options, in_index, in_bquery, in_rquery };
	int  where_in = in_options;


	// check to see if it is asking for help
	if ( argc <= 2 ) {
		print_help();
		return 0;
	}



	//---------------------------------------------------------
	// Handle Arguments
	//---------------------------------------------------------

	rankedquery[0] = 0;
	booleanquery[0] = 0;
	Display_Hits = false;
	Verbose_Mode = false;
	Interactive_Mode = false;
	Display_Text = false;

	char	*loc;
	int		count;
	for ( count = 1; count < argc; count++ ) {

		if ( argv[ count ][0] == '-' ) {
			
			loc = argv[ count ];
			loc++;

			while ( isalpha( *loc ) ) {
				switch (*loc) {
				case 'v':		Verbose_Mode = true;
								break;

				case 'd':		Display_Text = true;
								break;
		
				case 'i':		Interactive_Mode = true;
								break;

				case 'h':		Display_Hits = true;
								break;

				case 'g':		count++;
								first_hit = last_hit = atoi( argv[ count ] );
								break;

				case 'r':		count++;
								first_hit = atoi( argv[ count ] );
								count++;
								last_hit = atoi( argv[ count ] );
								break;

				case '?':		print_help();
								break;

				} // switch
				loc++;

			} // while isalpha

			continue; 

		} // if arv = '-'

		if ( where_in == in_options )
			where_in = in_index;


		if ( where_in == in_rquery ) {

			strcpy( (char *) rankedquery, argv[count]);	
		} 


		if ( where_in == in_bquery ) {

			strcpy( (char *) booleanquery, argv[count]);	

			// mark that the next string is the ranked query
			where_in = in_rquery;	

		} 


		// our first non-optional argument: the index path
		if ( where_in == in_index ) {

			strcpy( (char *) IndexPath, argv[ count ]);

			// mark that the next string is the boolean query
			where_in = in_bquery;	
	

			// setup the indexer
			if( prepare_indexer() != 0 )
				return 0;

			continue;

		} // index name

	
	} // for argv

	if ( Interactive_Mode ) {
		make_choice();
	}
	else {

		search();
	}

	if( close_indexer() ) {
		printf( "error closing indexer\n");
	}
	

	return 0;

}



#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -