Skip to content
Permalink
Browse files
Integrated IStreamConfiguration into QueryParser.
  • Loading branch information
MikeHopcroft committed Sep 11, 2016
1 parent c0a2f49 commit 74dc10d34854df1863cd7faf24303fca56bf0a11
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 14 deletions.
@@ -23,6 +23,6 @@ COMBINE_FILE_LISTS()


add_executable(QueryParser ${CPPFILES} ${PRIVATE_HFILES} ${PUBLIC_HFILES})
target_link_libraries(QueryParser Utilities Plan)
target_link_libraries(QueryParser Utilities Configuration Plan)
set_property(TARGET QueryParser PROPERTY FOLDER "examples")
set_property(TARGET QueryParser PROPERTY PROJECT_LABEL "QueryParser")
@@ -22,6 +22,8 @@

#include <iostream>

#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Exceptions.h"
#include "BitFunnel/Plan/QueryPipeline.h"
#include "BitFunnel/Plan/TermMatchNode.h"
@@ -61,7 +63,13 @@ namespace BitFunnel

std::cout << welcome;

QueryPipeline pipeline;
// Configure parser for three named streams.
auto streamConfiguration = Factories::CreateStreamConfiguration();
streamConfiguration->AddMapping("body", { 0 });
streamConfiguration->AddMapping("title", { 123 });
streamConfiguration->AddMapping("anchors", { 10 });

QueryPipeline pipeline(*streamConfiguration);

for (;;)
{
@@ -34,6 +34,7 @@ namespace BitFunnel

class IFileManager;
class IShardDefinition;
class IStreamConfiguration;

namespace Factories
{
@@ -45,5 +46,8 @@ namespace BitFunnel

std::unique_ptr<IShardDefinition> CreateShardDefinition();
std::unique_ptr<IShardDefinition> CreateShardDefinition(std::istream& input);

std::unique_ptr<IStreamConfiguration> CreateStreamConfiguration();
std::unique_ptr<IStreamConfiguration> CreateStreamConfiguration(std::istream& input);
}
}
@@ -29,16 +29,18 @@

namespace BitFunnel
{
class IStreamConfiguration;
class TermMatchNode;

class QueryPipeline
{
public:
QueryPipeline();
QueryPipeline(IStreamConfiguration const & streamConfiguration);

TermMatchNode const * ParseQuery(char const * query);

private:
IStreamConfiguration const & m_streamConfiguration;
std::unique_ptr<IAllocator> m_allocator;
};
}
@@ -20,12 +20,24 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Exceptions.h"
#include "StreamConfiguration.h"


namespace BitFunnel
{
std::unique_ptr<IStreamConfiguration> Factories::CreateStreamConfiguration()
{
return std::unique_ptr<IStreamConfiguration>(new StreamConfiguration());
}

std::unique_ptr<IStreamConfiguration> CreateStreamConfiguration(std::istream& /*input*/)
{
throw NotImplemented();
}


StreamConfiguration::StreamConfiguration()
{
}
@@ -27,6 +27,7 @@
#include <sstream>

#include "BitFunnel/Allocators/IAllocator.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Plan/TermMatchNode.h"
#include "BitFunnel/Utilities/StringBuilder.h"
#include "QueryParser.h"
@@ -35,8 +36,11 @@

namespace BitFunnel
{
QueryParser::QueryParser(std::istream& input, IAllocator& allocator)
QueryParser::QueryParser(std::istream& input,
IStreamConfiguration const & streamConfiguration,
IAllocator& allocator)
: m_input(input),
m_streamConfiguration(streamConfiguration),
m_allocator(allocator),
m_currentPosition(0),
m_haveChar(false)
@@ -305,10 +309,9 @@ namespace BitFunnel
}


Term::StreamId QueryParser::StreamIdFromText(char const * /*streamName*/) const
Term::StreamId QueryParser::StreamIdFromText(char const * streamName) const
{
// TODO: Return correct stream id here.
return 123;
return m_streamConfiguration.GetStreamId(streamName);
}


@@ -20,12 +20,15 @@
namespace BitFunnel
{
class IAllocator;
class IStreamConfiguration;
class TermMatchNode;

class QueryParser
{
public:
QueryParser(std::istream& input, IAllocator& allocator);
QueryParser(std::istream& input,
IStreamConfiguration const & streamConfiguration,
IAllocator& allocator);

TermMatchNode const * Parse();

@@ -90,6 +93,7 @@ namespace BitFunnel
Term::StreamId StreamIdFromText(char const * /*streamName*/) const;

std::istream& m_input;
IStreamConfiguration const & m_streamConfiguration;
IAllocator& m_allocator;

// Used for errors.
@@ -29,8 +29,9 @@

namespace BitFunnel
{
QueryPipeline::QueryPipeline()
: m_allocator(new Allocator(4096))
QueryPipeline::QueryPipeline(IStreamConfiguration const & streamConfiguration)
: m_streamConfiguration(streamConfiguration),
m_allocator(new Allocator(4096))
{
}

@@ -39,7 +40,7 @@ namespace BitFunnel
{
m_allocator->Reset();
std::stringstream s(query);
QueryParser parser(s, *m_allocator);
QueryParser parser(s, m_streamConfiguration, *m_allocator);
return parser.Parse();
}
}
@@ -26,6 +26,8 @@
#include <sstream>

#include "Allocator.h"
#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Plan/TermMatchNode.h"
#include "BitFunnel/Utilities/TextObjectFormatter.h"
#include "QueryParser.h"
@@ -47,7 +49,7 @@ namespace BitFunnel
{"Unigram(\"wat\", 0)", "wat"},

// STREAM:UNIGRAM.
{"Unigram(\"wat\", 123)", "StreamsAreCurrentlyIgnored:wat"},
{"Unigram(\"wat\", 1)", "stream:wat"},

// (UNIGRAM)
{"Unigram(\"wat\", 0)", "(wat)"},
@@ -439,7 +441,11 @@ namespace BitFunnel

std::stringstream s;
s << input;
QueryParser parser(s, allocator);

auto streamConfiguration = Factories::CreateStreamConfiguration();
streamConfiguration->AddMapping("body", { 123 });
streamConfiguration->AddMapping("stream", { 123 });
QueryParser parser(s, *streamConfiguration, allocator);

//std::cout << "input length: " << s.str().size() << std::endl;
std::cout
@@ -24,6 +24,8 @@
#include <iostream>
#include <thread> // sleep_for, this_thread

#include "BitFunnel/Configuration/Factories.h"
#include "BitFunnel/Configuration/IStreamConfiguration.h"
#include "BitFunnel/Exceptions.h"
#include "BitFunnel/Index/IDocument.h"
#include "BitFunnel/Index/IDocumentCache.h"
@@ -595,7 +597,8 @@ namespace BitFunnel
<< m_query
<< "\"" << std::endl;

QueryPipeline pipeline;
auto streamConfiguration = Factories::CreateStreamConfiguration();
QueryPipeline pipeline(*streamConfiguration);
auto tree = pipeline.ParseQuery(m_query.c_str());
if (tree == nullptr)
{

0 comments on commit 74dc10d

Please sign in to comment.